Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmN2MwNmI1Ni1lYjY2LTQwOWUtODJiNy02YTJkOWN' +
    'mMjQ1MzUiLCJpZCI6MjQyOTMsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1ODQ5NTI0NTZ9.MPzUjUdV6j0Up1RaDP3bquGUp8e5S4fUNRn' +
    'gyYrsytU'; //使用cesium数据源的许可/上传cesium使用

let viewer,point,point1,polyline,polyline1,xianpoint,polygon1,polygon2,handler22=null,canvas1,pickedObject,dianhandler=null,xianhandler=null;
//天地图key
var token = '5237c667340ff8305067974a8e6e173a';
let scene;
let camera;
let globe;
let canvas;
let ellipsoid;
let clock;
let baselayer;
let imagerylayer;
let selectedentity; //添加实体
let roll;
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
var handlerjiaodu;
var kuangqudwei;
var cbllist=[];//采剥量数组
var tempPoints_cbl=[];
var TDdata_point=[]

window.tilesets_DWGtest_Group = [];//定义倾斜的数组
window.tilesets_QX_Group = [];//定义倾斜的数组
window.tilesets_DWG_Group = [];//定义倾斜的数组
window.tilesets_DY_Group = [];//定义倾斜的数组
window.tilesets_GX_Group = [];//定义倾斜的数组
window.tilesets_SXT_Group=[];
window.tilesets_WL_Group=[];
window.tilesets_DXGX_Group=[];



$(function() {
    let options = {
        geocoder: false, //隐藏查找控件
        homeButton: true, //隐藏视角返回初始位置按钮
        sceneModePicker: false, //隐藏视角模式3D 2D CV
        animation: false, //隐藏动画控件
        baseLayerPicker: false, //隐藏图层选择
        fullscreenButton: false,
        vrButton: false,
        timeline: false, //隐藏时间线控件
        infoBox: false,   //详细弹窗不显示
        navigationHelpButton: false,
        navigationInstructionsInitiallyVisible: false,
        scene3DOnly: false,
        sceneMode: Cesium.SceneMode.SCENE3D,

        // 需要联网，调用的是网上的
        // terrainProvider: Cesium.createWorldTerrain({
        //     requestWaterMask: true,
        //     requestVertexNormals: true
        // }),
        contextOptions: {
            requestWebgl1: true,
        }
    };


    //跳转至中国区域
        viewer = new Cesium.Viewer('cesiumContainer', options);

    //深度探测
    //viewer.scene.globe.depthTestAgainstTerrain = true;

    // viewer.scene.preRender.addEventListener(function(scene, time) {
    //     // 获取帧率信息
    //     var fps = scene.frameState.fps;
    //
    //     // 检查 fps 是否为 undefined
    //     if (fps !== undefined) {
    //         // 打印帧率信息到控制台
    //         console.log('FPS:', fps.toFixed(2));
    //     }
    // });

    //设置显示帧率
   // viewer.scene.debugShowFramesPerSecond = true;

    // // 加载地形数据
    kuangqu()
//加载
    var terrainProvider = Cesium.createWorldTerrain({
        // url:"https://plat.casm.ac.cn/terrain",
        requestWaterMask: true, // 请求水体效果所需要的海岸线数据
        requestVertexNormals: true, // 请求地形照明数据
    });
    viewer.terrainProvider = terrainProvider;

    // var viewer = new Cesium.Viewer('cesiumContainer', {
    //     terrainProvider: new Cesium.CesiumTerrainProvider({
    //         url: 'https://plat.casm.ac.cn/terrain',
    //         requestWaterMask: true, // 请求水面遮罩
    //         requestVertexNormals: true // 请求顶点法线
    //     })
    // });

    var camera = viewer.camera;
    var position = Cesium.Cartesian3.fromDegrees(104.1954, 35.8617, 22023075.518522747); // 中国中心位置的经纬度，以及相机高度
    var heading = Cesium.Math.toRadians(0); // 相机的航向角度
    var pitch = Cesium.Math.toRadians(-90); // 相机的俯仰角度
    var roll = Cesium.Math.toRadians(0); // 相机的翻滚角度

    camera.setView({
        destination: position,
        orientation: {
            heading: heading,
            pitch: pitch,
            roll: roll
        }
    });


	//修改  人车
    window._viewer=viewer;
    // addentity();
    // console.log(window._viewer);

    viewer.cesiumWidget.creditContainer.style.display = 'none';
    //移除所有的底图
    viewer.imageryLayers.removeAll();
    camera = viewer.camera;

    viewer.scene.screenSpaceCameraController.enableCollisionDetection = false;
    viewer.scene.globe.translucency.enabled = false;

    canvas = viewer.canvas;
    canvas1=viewer.scene.canvas;
    scene = viewer.scene;
    globe = scene.globe;
    ellipsoid = globe.ellipsoid;
    clock = viewer.clock;

    const xmin = 119.06511782986772;
    const ymin = 45.895596882847872;
    const xmax = 119.15034266886764;
    const ymax = 45.9698186561991;
    Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(xmin, ymin, xmax, ymax);
    Cesium.Camera.DEFAULT_VIEW_FACTOR = 0.001;

    viewer.extend(Cesium.viewerDragDropMixin); //viewer扩展功能


    TDT_SL =new Cesium.WebMapTileServiceImageryProvider({
        url:'http://{s}.tianditu.gov.cn/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk='+token,
        layer:'vec',
        style:'default',
        format:'tiles',
        tileMatrixSetID:'w',
        subdomains:['t0','t1','t2','t3','t4','t5','t6','t7'],
        credit:new Cesium.Credit('天地图矢量'),
        maximumLevel:18
    })
//天地图影像
    TDT_YX =new Cesium.WebMapTileServiceImageryProvider({
        url:'http://{s}.tianditu.gov.cn/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk='+token,
        layer:'img',
        style:'default',
        format:'tiles',
        tileMatrixSetID:'w',
        subdomains:['t0','t1','t2','t3','t4','t5','t6','t7'],
        credit:new Cesium.Credit('天地图影像'),
        maximumLevel:18
    })
    //添加esri的地图作为底图
    let url = 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer';
    let esri = new Cesium.ArcGisMapServerImageryProvider({ url: url });
    viewer.imageryLayers.addImageryProvider(TDT_SL);
    viewer.imageryLayers.addImageryProvider(TDT_YX);
    viewer.imageryLayers.addImageryProvider(esri);
    viewer.imageryLayers._layers[0].show=false;
    viewer.imageryLayers._layers[1].show=false;
    viewer.imageryLayers._layers[2].show=true;



    //测量工具初始化
    window.measure = new CesiumMeasure(viewer);

    // var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
    //     url: 'https://218.92.41.142/gl/qingxie/hongyang/tileset.json', //数据地址
    //     // maximumScreenSpaceError: 2, //最大的屏幕空间误差
    //     // maximumNumberOfLoadedTiles: 1000, //最大加载瓦片个数
    //     // modelMatrix: m, //形状矩阵
    // }));
    //
    // viewer.flyTo(tileset);


    //加载管网
    function add3dtileslayer(url, namedata) {
        let options = {
            url: url,
            showOutline: false,
            //enableModelExperimental: true,
           // modelMatrix: Cesium.Matrix4.fromArray(code),
            style:Cesium.Cesium3DTileStyle({
                color: "vec4(0,0,1,0.5)"
            })

        };
        let tileslayer = new Cesium.Cesium3DTileset(options);
        let tilesets = viewer.scene.primitives.add(tileslayer);
        tilesets.name = namedata;
        window.tilesets_DXGX_Group.push(tilesets);

         //viewer.flyTo(tilesets)
    }


    function loadGeojsonLayer(node, callback) {
        Cesium.GeoJsonDataSource.load(node.url, {
            clampToGround: true
        }).then(function (dataSource) {
            // 获取数据源的实体集合
            var entities = dataSource.entities.values;

            // 根据属性自动配色
            entities.forEach(function (entity) {
                var prop = entity.properties;

                let options = {};
                try {
                    if (node.options != null) {
                        options = JSON.parse(node.options)
                    }
                } catch (error) {
                    console.error(error);
                }
                //判断数据类型，并配色
                if (entity.billboard) {
                    entity.billboard.pixelOffset = new Cesium.Cartesian2(0, -5);
                } else if (entity.polyline) {
                    entity.polyline.width = Cesium.defaultValue(options["width"], 5.0);
                    entity.polyline.material = Cesium.defaultValue(CesiumColorMapping(options["color"]), Cesium.Color.LIGHTSKYBLUE);
                } else if (entity.polygon) {
                    entity.polygon.material = Cesium.defaultValue(CesiumColorMapping(options["color"]), Cesium.Color.fromRandom({ alpha: 0.5 }));
                    entity.polygon.outline = Cesium.defaultValue(options["outline"], true);
                    entity.polygon.outlineColor = Cesium.defaultValue(CesiumColorMapping(options["outlineColor"]), Cesium.Color.LIGHTSKYBLUE);
                    entity.polygon.outlineWidth = Cesium.defaultValue(options["outlineWidth"], 2.0);

                    entity.polygon.classificationType = Cesium.ClassificationType.CESIUM_3D_TILE;
                }

            });

            viewer.dataSources.add(dataSource);
            viewer.flyTo(dataSource);
            callback(dataSource);
        });
    }


    var dwgurl='http://3510b38g11.zicp.fun:13894/qingxie/贺矿2(1)_reduce.geojson'
    // var dwgurl='http://localhost/贺矿2(1)_reduce.geojson'
    var banedata="贺矿2(1)_reduce"

    function adddwg(url, namedata) {
        let dataSource = new Cesium.GeoJsonDataSource(namedata);
        dataSource.load(url,{
            clampToGround: true
        }).then(function () {
             dataSource.show = false;
            viewer.dataSources.add(dataSource);
            window.tilesets_DWG_Group.push(dataSource)
        }).catch(function (error) {
            console.error(error);
        });

    }

    // adddwg(dwgurl,banedata)

    console.log("三维模型"+qydatalist_table)
    //加载点云
    function add3dtileslayer_DY(url,namedata) {
        let options = {
            url: url,
            name: namedata,
            showOutline: false,
            //enableModelExperimental: true,
            //modelMatrix: Cesium.Matrix4.fromArray(code),
            clampToGround: true //开启贴地
        };

        let tileslayer = new Cesium.Cesium3DTileset(options);
        let tilesets = viewer.scene.primitives.add(tileslayer);
        tilesets.name = namedata;
        // tilesets.style=new Cesium.Cesium3DTileStyle({
        //     color: "color('#22ee22', 1)"
        // })
        //viewer.flyTo(tilesets)
        window.tilesets_DY_Group.push(tilesets);
    }


    //加载点云
    function add3dtileslayer_DYtets(url, code) {
        let options = {
            url: url,
            showOutline: true,
            //enableModelExperimental: true,
            //modelMatrix: Cesium.Matrix4.fromArray(code),
            clampToGround: true //开启贴地
        };
        let tileslayer = new Cesium.Cesium3DTileset(options);
        let tilesets = viewer.scene.primitives.add(tileslayer);
        console.log("viewer===="+viewer)
        //tileslayer.show = false; // 设置默认关闭
        // tilesets.style=new Cesium.Cesium3DTileStyle({
        //     color: "color('#22ee22', 1)"
        // })
        viewer.flyTo(tilesets)
        // viewer.camera.flyTo({
        //     destination: Cesium.Cartesian3.fromDegrees(115.117308,28.969495)
        //
        // });

    }

    // viewer.camera.flyTo({
    //     destination: Cesium.Cartesian3.fromDegrees(115.117308,28.969495,900)
    //
    // });

    var tata='http://3510b38g11.zicp.fun:13894/qingxie/dianyun/testdata/tileset.json'
    //var tata='D:/Download/testdata/tileset.json'
    add3dtileslayer_DYtets(tata)

    //加载管线
    function add3dtileslayer_GX(url, namedata) {
        let options = {
            url: url,
            showOutline: false,
            enableModelExperimental: true,
            // modelMatrix: Cesium.Matrix4.fromArray(code),
            //modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(code)
            //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
            clampToGround: true //开启贴地
        };
        // options.modelMatrix[13] += 1300;
        // options.modelMatrix[12] += 90;  // 修改X坐标
        //
        // options.modelMatrix[14] += 90;  // 修改Z坐标
        // let translation = new Cesium.Cartesian3(-4, 6, -100);ckj01
        // Cesium.Matrix4.multiplyByTranslation(options.modelMatrix, translation, options.modelMatrix);
        let tileslayer = new Cesium.Cesium3DTileset(options);
        let tilesets = viewer.scene.primitives.add(tileslayer);
        tilesets.name = namedata;
       // viewer.flyTo(tilesets)

        window.tilesets_GX_Group.push(tilesets);
    }





    //加载倾斜
    function add3dtileslayer1(url, namedata) {
        let options = {
            url: url,
        };
        // window.tileslayer_QX = new Cesium.Cesium3DTileset(options);
        // window.tilesets_QX = viewer.scene.primitives.add(tileslayer_QX);
        // window.tilesets_QX_Group.push(tilesets_QX)

        let tileslayer = new Cesium.Cesium3DTileset(options);
        let tilesets = viewer.scene.primitives.add(tileslayer);
        tilesets.name = namedata;
        window.tilesets_QX_Group.push(tilesets)
    }

    let tilesurl1 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0101_3dtiles/tileset.json';
    let tilesurl2 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0102_3dtiles/tileset.json';
    let tilesurl3 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0103_3dtiles/tileset.json';
    let tilesurl4 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0104_3dtiles/tileset.json';
    let tilesurl5 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0105_3dtiles/tileset.json';

    let tilesurl8 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing2/0201_3dtiles/tileset.json';
    let tilesurl9 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing2/0202_3dtiles/tileset.json';
    let tilesurl10 = 'http://3510b38g11.zicp.fun:13894/qingxie/moxing2/0203_3dtiles/tileset.json';
    {'http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0101_3dtiles/tileset.json','http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0102_3dtiles/tileset.json','http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0103_3dtiles/tileset.json','http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0104_3dtiles/tileset.json','http://3510b38g11.zicp.fun:13894/qingxie/moxing1/0105_3dtiles/tileset.json'}

    let tilesurl6 = 'http://3510b38g11.zicp.fun:13894/qingxie/smartminepipeline/red_long/tileset.json';
    let tilesurl7 = 'http://3510b38g11.zicp.fun:13894/qingxie/smartminepipeline/yellow_short/tileset.json';
    let tilesurl11 = 'http://3510b38g11.zicp.fun:13894/qingxie/dwg/hekuang/tileset.json';
    let tilesurl12 = 'http://3510b38g11.zicp.fun:13894/qingxie/dwg/hekuang2/tileset.json';
    let tilesurl12test = 'http://3510b38g11.zicp.fun:13894/qingxie/dwg/test/tileset.json';
    //let tilesurl13 = 'http://localhost:8081/8y3dtiles/tileset.json';
     let tilesurl13 = 'http://3510b38g11.zicp.fun:13894/qingxie/dianyun/8y3dtiles/tileset.json';

    add3dtileslayer_GX(tilesurl6,[0.9864398675933796,-0.1302035259989476,0.09991711284758875,0,0.11051854643637493,0.9770485749676759,0.1821036327128731,0,-0.12133440779905415,-0.16859158926552542,0.9781895713577078,0,-4083.017168224789,-3268.634292630013,-2300.52889355924,1])
    add3dtileslayer_GX(tilesurl7,[0.9864398675933796,-0.1302035259989476,0.09991711284758875,0,0.11051854643637493,0.9770485749676759,0.1821036327128731,0,-0.12133440779905415,-0.16859158926552542,0.9781895713577078,0,-4083.017168224789,-3268.634292630013,-2300.52889355924,1])


    qydatalist_table.forEach(function (item,index){
        if (item.category=="三维模型"){
            // console.log("三维模型"+item.url)
            let dataurl=item.url
            let arr = dataurl.split(",");
            arr.forEach(function (itemurl,index){
                add3dtileslayer1(itemurl.substring(1, itemurl.length - 1),item.name)
            })
            window.tilesets_QX_Group.forEach((item, index) => {
                    item.show = false;
            })
        }else if (item.category=="DWG文件"){
            // let arr = item.url.split(",");
            // arr.forEach(function (itemurl,index){
            //     add3dtileslayer1(itemurl.substring(1, itemurl.length - 1),item.name)
            // })
            // if (item.url.find('矢量数据')){
                // http://3510b38g11.zicp.fun:13894/dwg/hekuang_reduce.geojson
                let fileName = item.url.split('/').pop()
                var dwguri='http://3510b38g11.zicp.fun:13894/dwg/'+fileName
                console.log("dwguri"+dwguri)
                adddwg(dwguri,item.name)
            // }

        }
        else if(item.category=="矢量图层"){

            // let arr = item.url.split(",");
            // arr.forEach(function (itemurl,index){
            //     add3dtileslayer1(itemurl.substring(1, itemurl.length - 1),item.name)
            // })
            // if (item.url.find('矢量数据')){
                let fileName = item.url.split('/').pop()
                console.log(fileName)
                var dwguri='http://3510b38g11.zicp.fun:13894/dwg/'+fileName
                console.log(dwguri)
                adddwg(dwguri,item.name)
            // }


        }
        else if (item.category=="点云数据"){
            let dataurl=item.url
            let arr = dataurl.split(",");
            arr.forEach(function (itemurl,index){
                add3dtileslayer_DY(itemurl.substring(1, itemurl.length - 1),item.name)
            })

            window.tilesets_DY_Group.forEach((item, index) => {
                    item.show = false;
            })
            // add3dtileslayer_DY(String(item.url),item.name)
        }
    })

    // add3dtileslayer_DWG_test(tilesurl12test)


})



//矿区标识
function kuangqu(){
        kuangqudwei=viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(119.122076872,45.933504747, 0.61),
            name: "平朔矿区",
            billboard: {
            // 图像地址，URI或Canvas的属性
            image: './images/矿区定位.png',
            // 设置颜色和透明度
            color: Cesium.Color.WHITE.withAlpha(1),
            // 高度（以像素为单位）
            height: 100,
            // 宽度（以像素为单位）
            width: 100,
            // 逆时针旋转
            rotation: 0,
            // 大小是否以米为单位
            sizeInMeters: false,
            // 相对于坐标的垂直位置
            //verticalOrigin: Cesium.VerticalOrigin.CENTER,
            // 相对于坐标的水平位置
            //horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
            // 该属性指定标签在屏幕空间中距此标签原点的像素偏移量
            pixelOffset: new Cesium.Cartesian2(0, 65),
            // 应用于图像的统一比例。比例大于会1.0放大标签，而比例小于会1.0缩小标签。
            scale: 1.0,
            // 显示在距相机的距离处的属性，多少区间内是可以显示的
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(70000, 15000000000),
            // 是否显示
            show: true
        },
    });
    kuangqudwei.label={
        text:'平朔矿区' ,
        font: '14pt monospace',
        // showBackground:true,                //是否显示背景颜色
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        fillColor: Cesium.Color.fromCssColorString('#F73709'),
        outlineColor: Cesium.Color.fromCssColorString('#67360d'),
        disableDepthTestDistance: Number.POSITIVE_INFINITY,
        distanceDisplayCondition: new Cesium.DistanceDisplayCondition(70000, 15000000000),
        // scaleByDistance : new Cesium.NearFarScalar(100, 2, 500, 0.0),
        outlineWidth: 3,
        verticalOrigin: Cesium.VerticalOrigin.TOP,
        pixelOffset: new Cesium.Cartesian2(0, -5)//此属性为设置偏移量
    }
    // viewer.camera.flyTo({
    //     destination: Cesium.Cartesian3.fromDegrees(119.122076872,45.933504747, 8000)
    //
    // });

    //添加点击事件
    var handlerkuangqu = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);//viewer.scene.
    handlerkuangqu.setInputAction(function( click) {

        let cartesian = viewer.camera.pickEllipsoid(click.position);
        let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
        let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度

        var pick = viewer.scene.pick(click.position);
        if(pick!==null && pick){

            if (pick.id!==null&& pick.id){

                if (pick.id._name =='平朔矿区'){
                    viewer.camera.flyTo({


                        // destination: Cesium.Cartesian3.fromDegrees(119.122076872,45.933504747, 8000)
                        // destination: Cesium.Cartesian3.fromDegrees(119.122076872,45.933504747, 8000)
                        destination: Cesium.Cartesian3.fromDegrees( 119.1221,45.9335, 8000)
                    });
                }
            }

        }

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

}




//添加图片
var poinArr = [{
    id:101,
        position: {
        x: 119.11909136365044,
        y: 45.931603491016276
    },
    text: 'S-01'
}, {
    id:102,
    position: {
        x: 119.1312879871568,
        y: 45.91923518067756
    },
    text: 'S-02'
}, {
    id:103,
    position: {
        x: 119.11495363927054,
        y: 45.91727487070917
    },
    text: 'S-03'
},
    {
        id:104,
        position: {
            x: 119.11739601538697,
            y: 45.91253407902784
        },
        text: 'S-04'
    },
    {
        id:105,
        position: {
            x: 119.12800925226522,
            y: 45.919516952816906
        },
        text: 'S-05'
    },
    {
        id:106,
        position: {
            x: 119.12981248807075,
            y: 45.92899648373316
        },
        text: 'S-06'
    }
]
var adata=0
function addimg1() {
    for(var i=101;i<107;i++){
        viewer.entities.removeById(i);
        // console.log(i)
    }
    $('#moxing').hide();
    $("#bpxx").hide();
    $("#BpPoint_information_div").hide()
    $("#catname").text('监控监测')
    if (adata==0){
        $("#dataselecr_id").show();
        adata=1
    }else {
        $("#dataselecr_id").hide();
        adata=0
    }

    if (handler){
        //移除点击事件
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
    }
    //console.log(viewer)


    poinArr.map(res => {
        var poin = viewer.entities.add({
            id:res.id,
            type:'camera',
            position: Cesium.Cartesian3.fromDegrees(res.position.x, res.position.y,996), //110.20,34.55
            billboard: {
                // 图像地址，URI或Canvas的属性
                image: './images/shexiangtou.png',
                // 设置颜色和透明度
                color: Cesium.Color.WHITE.withAlpha(0.8),
                // 高度（以像素为单位）
                height: 60,
                // 宽度（以像素为单位）
                width: 60,
                // 逆时针旋转
                rotation: 0,
                // 大小是否以米为单位
                sizeInMeters: false,
                // 相对于坐标的垂直位置
                // verticalOrigin: Cesium.VerticalOrigin.CENTER,
                // 相对于坐标的水平位置
                //horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                // 该属性指定标签在屏幕空间中距此标签原点的像素偏移量
                pixelOffset: new Cesium.Cartesian2(10, 0),
                eyeOffset: new Cesium.Cartesian3(0.0, 0.0, 0.0), // default
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                alignedAxis: Cesium.Cartesian3.ZERO, // default
                // 应用于图像的统一比例。比例大于会1.0放大标签，而比例小于会1.0缩小标签。
                scale: 1.0,
                // 显示在距相机的距离处的属性，多少区间内是可以显示的
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 9000),
                // 是否显示
                show: true
            },
            label: {
                text:res.text ,
                font: '14pt monospace',
                // showBackground:true,                //是否显示背景颜色
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                fillColor: Cesium.Color.fromCssColorString('#F73709'),
                outlineColor: Cesium.Color.fromCssColorString('#67360d'),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 9000),
                // scaleByDistance : new Cesium.NearFarScalar(100, 2, 500, 0.0),
                outlineWidth: 3,
                verticalOrigin: Cesium.VerticalOrigin.TOP,
                pixelOffset: new Cesium.Cartesian2(10, 0)//此属性为设置偏移量
            },


        });
        //添加至数组
        window.tilesets_SXT_Group.push(poin);
        viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(res.position.x, res.position.y, 8000)

        });
        //隐藏所有摄像头图标
        window.tilesets_SXT_Group.forEach((item, index) => {
            item.show = false
        })

        //添加点击事件
        var handler1 = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);//viewer.scene.
        handler1.setInputAction(function(
            click) {

            let cartesian = viewer.camera.pickEllipsoid(click.position);
            let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
            let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
            let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度

            var pick = viewer.scene.pick(click.position);

            if (pick.primitive.id !=null) {//pick || pick.id == "Entity"
                //console.log(res.position.x, res.position.y)
                if(pick.id._type =='camera'){
                    viewer.flyTo(pick.id);
                    $("#vido").show();
                    $("#moxing").hide();
                    $("#moxing1").hide();
                    videoshow(pick);
                }
            } else {
                console.log('不是');
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    })
}

//添加图片


//摄像头传输
function videoshow(pick){
    if (Hls.isSupported()) {
        let video = document.getElementById('videoid');
        // video.display='block';
        var hls = new Hls();
        hls.loadSource('https://hls01open.ys7.com/openlive/84fd148491834c80be8c904abbd40a1b.m3u8');
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED, function () {
        });
    }
    Add_sxt_information(pick);
    let video = document.getElementById('videoid');
    video.play();
}

//按钮关闭
function showbutton() {
    let video = document.getElementById('videoid');
    video.pause();
    $("#vido").hide();
}
// // 加载模型并flyTo那里
// function gl_position() {
//     var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
//         url: '', //数据地址
//         // maximumScreenSpaceError: 2, //最大的屏幕空间误差
//         // maximumNumberOfLoadedTiles: 1000, //最大加载瓦片个数
//         // modelMatrix: m, //形状矩阵
//     }));
//     viewer.flyTo(tileset);
// };
// 加载模型并flyTo那里




//点击改变颜色







//三维坐标获取
//三维坐标获取
function zuobiao(){
    // for(var i=101;i<107;i++){
    //     viewer.entities.removeById(i);
    //     console.log(i)
    // }
    viewer.entities.removeById(1000);
    // viewer.scene.globe.depthTestAgainstTerrain = true;
    scene = viewer.scene;
    //var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
    handler.setInputAction(function(evt) {


        var scene = viewer.scene;
        if (scene.mode !== Cesium.SceneMode.MORPHING) {

            //var pickedObject = scene.pick(evt.position);
            var pickedObject = scene.pick(evt.position);
            if (scene.pickPositionSupported && Cesium.defined(pickedObject)) {
                var cartesian = viewer.scene.pickPosition(evt.position);

                if (Cesium.defined(cartesian)) {
                    $("#moxing").show();
                    var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    var lng = Cesium.Math.toDegrees(cartographic.longitude);
                    var lat = Cesium.Math.toDegrees(cartographic.latitude);
                    var height = cartographic.height;//模型高度
                    let mapPosition={x:lng,y:lat,z:height};

                    td1.innerHTML =lng;
                    td2.innerHTML =lat;
                    td3.innerHTML =height;
                    $("#vido").hide();
                }else {
                    $("#moxing").hidden();
                }
            }
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

// 创建角度标记
function createAngleMarker(firstPoint,secondPoint,thirdPoint) {
    var firstPoint1={x:firstPoint.x,y:firstPoint.y}
    var secondPoint1={x:secondPoint.x,y:secondPoint.y}
    var thirdPoint1={x:thirdPoint.x,y:thirdPoint.y}

    // var angleLibrary = Cesium.AngleGeometryLibrary;
    // var angle = angleLibrary.computeAngleBetweenThreePoints(
    //     firstPoint,
    //     secondPoint1,
    //     thirdPoint1
    // );
    //
    var vector1 = Cesium.Cartesian3.subtract(secondPoint, firstPoint, new Cesium.Cartesian3());
    var vector2 = Cesium.Cartesian3.subtract(secondPoint,thirdPoint, new Cesium.Cartesian3());

    var angle = Cesium.Cartesian3.angleBetween(vector1, vector2);
    var angledata=Cesium.Math.toDegrees(angle)


    var angleMarker = viewer.entities.add({
        polyline: {
            positions:[
                firstPoint,
                secondPoint,
                thirdPoint,
            ],
            width: 5,
            material: Cesium.Color.RED,
        },

    });


    angleMarker.label={
        text:angledata,
        color : Cesium.Color.fromCssColorString('#E73C18'),
        font:'normal 32px MicroSoft YaHei',
        showBackground : true,
        scale : 0.5,
        horizontalOrigin : Cesium.HorizontalOrigin.LEFT_CLICK,
        verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
        disableDepthTestDistance : 100000.0
    }

    handlerjiaodu.destroy();
    return angleMarker,angledata;

}


//测量角度函数

function measurejaiodu(){

    handlerjiaodu = new Cesium.ScreenSpaceEventHandler(scene.canvas);

    var firstPoint = undefined;
    var secondPoint = undefined;
// 处理鼠标单击事件
    handlerjiaodu.setInputAction(function (click) {
        var cartesian = getCatesian3FromPX1(click.position);
        let ray = viewer.camera.getPickRay(click.position);
        // 查找射线与渲染的地球表面之间的交点。射线必须以世界坐标给出。返回Cartesian3对象
        let position = viewer.scene.globe.pick(ray, viewer.scene);
        // var cartesian = viewer.scene.pickPosition(click.position);
            var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
            var lng = Cesium.Math.toDegrees(cartographic.longitude);
            var lat = Cesium.Math.toDegrees(cartographic.latitude);
            var height = cartographic.height;//模型高度
            let mapPosition={x:lng,y:lat,z:height};
        var pickedObject = scene.pick(click.position);

        if ( !firstPoint) {
            // 选择第一个点
            firstPoint = cartesian;

            viewer.entities.add({
                name: "点",
                position:firstPoint, // 点生成的位置
                point: {
                    color: Cesium.Color.DEEPSKYBLUE,	// 点颜色
                    outlineColor: Cesium.Color.SKYBLUE,	// 点边框颜色
                    pixelSize: 7,						// 点大小
                    outlineWidth: 2,					// 点边框大小
                    disableDepthTestDistance: Number.POSITIVE_INFINITY,		 // 受地形遮挡
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 生成在地形表面

                }
            });

        } else if ( firstPoint && !secondPoint) {
            // 选择第二个点
            secondPoint = cartesian;
            viewer.entities.add({
                name: "点",
                position: secondPoint, // 点生成的位置
                point: {
                    color: Cesium.Color.DEEPSKYBLUE,	// 点颜色
                    outlineColor: Cesium.Color.SKYBLUE,	// 点边框颜色
                    pixelSize: 7,						// 点大小
                    outlineWidth: 2,					// 点边框大小
                    disableDepthTestDistance: Number.POSITIVE_INFINITY,		 // 受地形遮挡
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 生成在地形表面
                }
            });
        } else if ( firstPoint && secondPoint) {
            // 选择第三个点，创建角度标记
            var thirdPoint = cartesian;
           var data= createAngleMarker(firstPoint,secondPoint,thirdPoint);

            viewer.entities.add({
                name: "点",
                position: thirdPoint, // 点生成的位置
                point: {
                    color: Cesium.Color.DEEPSKYBLUE,	// 点颜色
                    outlineColor: Cesium.Color.SKYBLUE,	// 点边框颜色
                    pixelSize: 7,						// 点大小
                    outlineWidth: 2,					// 点边框大小
                    disableDepthTestDistance: Number.POSITIVE_INFINITY,		 // 受地形遮挡
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 生成在地形表面
                }
            });

            firstPoint = undefined;
            secondPoint = undefined;
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

function measurejiaoduii(){
    $("#echartsView1").hide();
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    measure.drawLineMeasureGraphics1()
}

// 测量距离函数
function measuredistance() {
    $('#tishi').show()
    $("#echartsView1").hide();
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#moxing").hide();
    $("#moxing1").hide();
    $("#xianxxxx").hide();
    $("#dianxxxx").hide();
    $("#mianxxxx").hide();

    viewer.entities.remove(point1);
    measure.drawLineMeasureGraphics();
}

// 测量面积函数
function measurearea() {
    $('#tishi').show()
    $("#echartsView1").hide();
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#moxing").hide();
    $("#moxing1").hide();
    $("#xianxxxx").hide();
    $("#dianxxxx").hide();
    $("#mianxxxx").hide();
    viewer.entities.remove(point1);

    measure.drawAreaMeasureGraphics();
}

// 测量高度函数
function measureheight() {
    $('#tishi').hide()
    $("#echartsView1").hide();

    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#moxing").hide();
    $("#moxing1").hide();
    $("#xianxxxx").hide();
    $("#dianxxxx").hide();
    $("#mianxxxx").hide();
    viewer.entities.remove(point1);

    measure.drawTrianglesMeasureGraphics();
}

// 清除测量标记函数
function measureclear() {
    window.tilesets_DWG_Group.forEach((item, index) => {
            item.show = false;
    })

    numb=0
    adata=0
    xianid=0
    $('#tishi').hide()
    $('#dataselecr_id').hide()

    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    try{
        $("#moxing").hide();
        $("#moxing1").hide();
        $("#xianxxxx").hide();
        $("#dianxxxx").hide();
        $("#mianxxxx").hide();
        viewer.entities.remove(point1);
        measure._drawLayer.entities.removeAll();

        viewer.entities.removeAll();
    }catch (e) {

    }
    kuangqu()
}

function test(){
      var positions = Cesium.Cartesian3.fromDegreesArray([
        119.109,45.927,
                        119.11314625289906,45.92523460477587,
                        119.11864489736554,45.9250517668999,
        // ...
    ]);
    var entity = viewer.entities.add({
        polygon: {
            hierarchy: positions,
            material: Cesium.Color.RED.withAlpha(0.5),
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            // clampToGround: true,

            // classificationType: Cesium.ClassificationType.CESIUM_3D_TILE,
        }
    });

    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(  119.109,45.927, 500)
    });
}


//数据查询部分
//查询视角跳转
function showpopup(e) {
    $('#DetailedInformation_A').show();
    document.getElementById('DetailedInformation_text').style.display='block';
    var position = $(e.getElementsByTagName('div')[2]).text().split(/[：;]/);

    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(position[3], position[1]-0.009, 500),
        orientation: {
            heading:Cesium.Math.toRadians(0),
            pitch:Cesium.Math.toRadians(-20),
            roll:0,
            //range:500
        }
    });
    AddDetailData(e);
}
//添加图标
function AddIcon(lat,lon,id,url){
    viewer.entities.add({
        id:id,
        position: Cesium.Cartesian3.fromDegrees(lon, lat, 940         ),
        billboard: {
            // 图像地址，URI或Canvas的属性
            // image: './images/位置.png',
            image: url,
            // 设置颜色和透明度
            color: Cesium.Color.WHITE.withAlpha(1),
            // 高度（以像素为单位）
            height: 116,
            // 宽度（以像素为单位）
            width: 104,
            // 逆时针旋转
            rotation: 0,
            // 大小是否以米为单位
            sizeInMeters: false,
            // 相对于坐标的垂直位置
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            // 相对于坐标的水平位置
            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
            // 该属性指定标签在屏幕空间中距此标签原点的像素偏移量
            pixelOffset: new Cesium.Cartesian2(0, 0),
            // 应用于图像的统一比例。比例大于会1.0放大标签，而比例小于会1.0缩小标签。
            scale: 1,
            // 显示在距相机的距离处的属性，多少区间内是可以显示的
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 11000),
            // 是否显示
            show: true,
            //根据广告牌与相机的距离，获取或设置广告牌的远近缩放属性。
            scaleByDistance:new Cesium.NearFarScalar(100,1,10000,0.5)
        },

    });
}



//移除实体
function CloseEntities1(){
    // 根据entity（实体）对象删除
    //viewer.entities.remove()
    // 根据ID删除


    for(var i=0;i<idstr.length;i++){
        viewer.entities.removeById(idstr[i]);

    }
    $('#List').hide();
    //viewer.entities.removeById();
    // 删除全部
    viewer.entities.removeAll()
    //$('#moxing').hide();
}
//获取坐标
function getC(){
    var handler = new Cesium.ScreenSpaceEventHandler(canvas);

    handler.setInputAction(function (movement) {

        var position = scene.pickPosition(movement.position);


        let radiansPos = Cesium.Cartographic.fromCartesian(position);

        getBit(Cesium.Math.toDegrees(radiansPos.longitude), Cesium.Math.toDegrees(radiansPos.latitude),Cesium.Math.toDegrees(radiansPos.height));

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    function getBit(value_lon, value_lat,value_hei) {
        let lon = Number(value_lon);
        lon = lon.toFixed('7');
        let lat = Number(value_lat);
        lat = lat.toFixed('7');

        //return str;
    }
}
//坐标转换公式
function delta(lat, lon) {
    let PI =3.14159265358979324
    let x_pi = 3.14159265358979324 * 3000.0 / 180.0
    var a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
    var ee = 0.00669342162296594323; //  ee: 椭球的偏心率。
    var x=lon - 105.0
    var y=lat-35.0
    var ret1 = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
    ret1 += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
    ret1 += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
    ret1 += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
    var dLat =ret1
    var ret2 = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
    ret2+= (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
    ret2 += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
    ret2 += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
    var dLon =ret2
    var radLat = lat / 180.0 * PI;
    var magic = Math.sin(radLat);
    magic = 1 - ee * magic * magic;
    var sqrtMagic = Math.sqrt(magic);
    dLat = -10000000.0*(dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
    dLon = 10000000.0*(dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * PI);
    return {'lat': dLat, 'lon': dLon};
}

function start(lng,lat) {
    // var B = document.getElementById("lat").value;
    // var L = document.getElementById("lon").value;
    // var L0 = document.getElementById("L0").value;
    // var n = document.getElementById("n").value;

    // var B=37.6518170666666;
    // var L=111.94631089722221;

    var B=lat;
    var L=lng;

    var L0=Math.round(L/3)*3;
    var n=3;



    var [x, y] = BL2xy(B, L, L0, n)
    return [x,y]

};



function BL2xy(B, L, L0, n) {
    // 将角度转换为弧度
    B = degToRad(B);
    L = degToRad(L);
    L0 = degToRad(L0);

    // 定义椭球参数
    var a = 6378137;
    var b = 6356752.3142;
    var e1 = (Math.sqrt(a * a - b * b)) / b;

    // 计算子午线弧长
    var X = get_X(B, a, b, e1);

    var V = Math.sqrt(1 + e1 * e1 * Math.pow(Math.cos(B), 2));
    var c = a * a / b;
    var N = c / V;
    var t = Math.tan(B);
    var n = Math.sqrt(e1 * e1 * Math.pow(Math.cos(B), 2));
    var l = L - L0;

    var xp1 = X;
    var xp2 = (N * Math.sin(B) * Math.cos(B) * Math.pow(l, 2)) / 2;
    var xp3 = (N * Math.sin(B) * Math.pow(Math.cos(B), 3) * (5 - Math.pow(t, 2) + 9 * Math.pow(n, 2) + 4 * Math.pow(n, 4)) * Math.pow(l, 4)) / 24;
    var xp4 = (N * Math.sin(B) * Math.pow(Math.cos(B), 5) * (61 - 58 * Math.pow(t, 2) + Math.pow(t, 4)) * Math.pow(l, 6)) / 720;

    var x = xp1 + xp2 + xp3 + xp4;

    var yp1 = N * Math.cos(B) * l;
    var yp2 = (N * Math.pow(Math.cos(B), 3) * (1 - Math.pow(t, 2) + Math.pow(n, 2)) * Math.pow(l, 3)) / 6;
    var yp3 = (N * Math.pow(Math.cos(B), 5) * (5 - 18 * Math.pow(t, 2) + Math.pow(t, 4) + 14 * Math.pow(n, 2) - 58 * Math.pow(n, 2) * Math.pow(t, 2)) * Math.pow(l, 5)) / 120;

    var y = yp1 + yp2 + yp3 + 500000;

    return [x, y];
}

// 辅助函数：将角度转换为弧度
function degToRad(degrees) {
    return degrees * (Math.PI / 180);
}

function get_X(B, a, b, e2) {
    // get_X是子午线弧长计算函数
    // 输入纬度B（弧度）
    // 输入参数椭球长半轴a，短半轴b，第二偏心率e2
    // 输出参数子午线弧长
    e2 = Math.pow(e2, 2);
    var b0 = 1 - (3 * e2) / 4 + (45 * Math.pow(e2, 2)) / 64 - (175 * Math.pow(e2, 3)) / 256 + (11025 * Math.pow(e2, 4)) / 16384;
    var b2 = b0 - 1;
    var b4 = (15 * Math.pow(e2, 2)) / 32 - (175 * Math.pow(e2, 3)) / 384 + (3675 * Math.pow(e2, 4)) / 8192;
    var b6 = (-35 * Math.pow(e2, 3)) / 96 + (735 * Math.pow(e2, 4)) / 2048;
    var b8 = (315 * Math.pow(e2, 4)) / 1024;
    var c = a * a / b;
    var X = c * (b0 * B + (b2 * Math.cos(B) + b4 * Math.pow(Math.cos(B), 3) + b6 * Math.pow(Math.cos(B), 5) + b8 * Math.pow(Math.cos(B), 7)) * Math.sin(B));
    return X;
}

//三维模型拾取
 function getCatesian3FromPX(px) {

    if (this._viewer && px) {
        var picks = this._viewer.scene.drillPick(px)
        var cartesian = null;
        var isOn3dtiles = false,
            isOnTerrain = false;
        // drillPick
        for (let i in picks) {
            let pick = picks[i]

            if (pick &&
                pick.primitive instanceof Cesium.Cesium3DTileFeature ||
                pick && pick.primitive instanceof Cesium.Cesium3DTileset ||
                pick && pick.primitive instanceof Cesium.Model) { //模型上拾取
                isOn3dtiles = true;
            }
            // 3dtilset
            if (isOn3dtiles) {
                this._viewer.scene.pick(px) // pick
                cartesian = this._viewer.scene.pickPosition(px);
                if (cartesian) {
                    let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    if (cartographic.height < 0) cartographic.height = 0;
                    let lon = Cesium.Math.toDegrees(cartographic.longitude),
                        lat = Cesium.Math.toDegrees(cartographic.latitude),
                        height = cartographic.height;
                    cartesian = this.transformWGS84ToCartesian({
                        lng: lon,
                        lat: lat,
                        alt: height
                    })

                }
            }
        }
        // 地形
        let boolTerrain = this._viewer.terrainProvider instanceof Cesium
            .EllipsoidTerrainProvider;
        // Terrain
        if (!isOn3dtiles && !boolTerrain) {
            var ray = this._viewer.scene.camera.getPickRay(px);
            if (!ray) return null;
            cartesian = this._viewer.scene.globe.pick(ray, this._viewer.scene);
            isOnTerrain = true
        }
        // 地球
        if (!isOn3dtiles && !isOnTerrain && boolTerrain) {

            cartesian = this._viewer.scene.camera.pickEllipsoid(px, this._viewer.scene.globe
                .ellipsoid);
        }
        if (cartesian) {
            let position = this.transformCartesianToWGS84(cartesian)
            if (position.alt < 0) {
                cartesian = this.transformWGS84ToCartesian(position, 0.1)
            }
            return cartesian;
        }
        return false;
    }

}
//添加坐标点
function _addInfoPoint(position) {


    let _labelEntity = new Cesium.Entity();
    _labelEntity.name = '标注';
    _labelEntity.position = position
    _labelEntity.point = {
        pixelSize: 10,
        outlineColor: Cesium.Color.BLUE,
        outlineWidth: 5,
        disableDepthTestDistance: Number.POSITIVE_INFINITY
        //clampToGround: true,
    }
    _labelEntity.label = {
        text: '米',//公里米
        show: true,
        showBackground: true,
        font: '14px monospace',
        horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
        pixelOffset: new Cesium.Cartesian2(-20, -1), //left top
        disableDepthTestDistance: Number.POSITIVE_INFINITY,
        heightReference:Cesium.HeightReference.CLAMP_TO_GROUND,
        clampToGround:true , //是否贴地
        //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        //disableDepthTestDistance: Number.POSITIVE_INFINITY,
    }
    viewer.entities.add(_labelEntity)
}


//三维模型坐标获取
var swzbid=[];
var swzbnum=10066;
function adddian1(){
    $('#tishi').show()
    viewer.entities=[]
    console.log(viewer.entities)
    if(WlPoint_Group!=[]){
        WlPoint_Group.forEach((item,index)=>{
            item.ellipse.semiMinorAxis=7;
            item.ellipse.semiMajorAxis=7;
            item.billboard.height=7;
            item.billboard.width=7;
        })
    }
    $("#dianxxxx1").hide();
    $("#echartsView1").hide();

    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }


    $("#dianxxxx1").hide();
    $("#xianxxxx").hide();
    $("#xianxxxx1").hide();
    $("#dianxxxx").hide();
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    for(var i=0;i<=swzbid.length;i++){
        viewer.entities.removeById(swzbid[i]);

    }
    var ellipsoid=viewer.scene.globe.ellipsoid;
    var body=document.querySelector("body");
    body.style.cursor="crosshair";
    // viewer.scene.globe.depthTestAgainstTerrain = true;
    handler22 = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    // 监听鼠标左键
    handler22.setInputAction(function (event) {
        for(var i=0;i<=swzbid.length;i++){
            viewer.entities.removeById(swzbid[i]);
        }

        var cartesian = getCatesian3FromPX(event.position);

        //var cartesian=viewer.camera.pickEllipsoid(event.position,ellipsoid)
        var carto=viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian)
        var haiba=viewer.scene.globe.getHeight(carto);


        // 从相机位置通过windowPosition 世界坐标中的像素创建一条射线。返回Cartesian3射线的位置和方向。
        let ray = viewer.camera.getPickRay(event.position);
        // 查找射线与渲染的地球表面之间的交点。射线必须以世界坐标给出。返回Cartesian3对象
        let position = viewer.scene.globe.pick(ray, viewer.scene);

        if (scene.mode !== Cesium.SceneMode.MORPHING){
            var pickedObject = scene.pick(event.position);
            if (scene.pickPositionSupported && Cesium.defined(pickedObject)){
                tesian = viewer.scene.pickPosition(event.position);
                var cartesian = viewer.scene.pickPosition(event.position);
                if (Cesium.defined(cartesian)){
                    $("#moxing").show();
                    var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    var lng = Cesium.Math.toDegrees(cartographic.longitude);
                    var lat = Cesium.Math.toDegrees(cartographic.latitude);
                    var height = cartographic.height;//模型高度
                    let mapPosition={x:lng,y:lat,z:height};

                    // var cartesian = viewer.scene.pickPosition(event.position);
                    // var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    // var lng = Cesium.Math.toDegrees(cartographic.longitude);
                    // var lat = Cesium.Math.toDegrees(cartographic.latitude);
                    // var height = cartographic.height; //模型高度

                    point1 = viewer.entities.add({
                        name: "三维模型",
                        id:swzbnum+=1,
                        position: cartesian,
                        point: {
                            color: Cesium.Color.SKYBLUE,
                            pixelSize: 7,
                            outlineColor: Cesium.Color.YELLOW,
                            outlineWidth: 2,
                            clampToGround:true, //是否贴地
                            disableDepthTestDistance:99000000,
                        },

                    });
                    //_addInfoPoint(cartesian)
                    swzbid.push(swzbnum);
                    console.log(point1)
                    td1.innerHTML =lng.toFixed(9);
                    td2.innerHTML =lat.toFixed(9);
                     var datasy=start(lng,lat)

                    td3.innerHTML =height.toFixed(4);

                     td12.innerHTML=datasy[0].toFixed(4);
                     td223.innerHTML=datasy[1].toFixed(4);
                    $("#vido").hide();
                    $("#moxing1").css({"left":"238px"});

                }else{
                    $("#moxing").hide();
                    $("#moxing1").css({"left":"0px"});
                }
            }else {
                $("#moxing").hide();
                $("#moxing1").css({"left":"0px"});
            }

            $("#moxing1").show();
        }

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // 右击单击停止绘制
    handler.setInputAction(function () {
        if (handler22!==null){
            handler22.destroy(); //关闭事件句柄
            handler22 = null;
        }

        //var body=document.querySelector("body");
        body.style.cursor="default";
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

}
//点线面修改

function  mianji(){
    $("#dianxxxx1").hide();
    $("#dianxxxx").hide();
    $("#xianxxxx").hide();
    $("#xianxxxx1").hide();
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    pickedObject=null;
    var handlerdxmclick = new Cesium.ScreenSpaceEventHandler(canvas1);
    handlerdxmclick.setInputAction(function (event) {
        pickedObject = scene.pick(event.position);

        if (pickedObject && pickedObject.id) {
            //对对应的点的操作

            if (pickedObject.id._polygon!== null) {
                //pickedObject.id._label._text._value="22"
                //xianxxxx1

                $("#mianxxxx1").show();
                $("#midbutton1").click(function(){
                    var value=$("#midinput1").val();

                    if (value.length>0){
                        polygon1. label.text._value=value;
                        mtd441.innerHTML =value;

                    }else {
                        alert("不能为空")
                    }

                })
                mtd441.innerHTML=mianid+"号面";
                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#mysxz1',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                            redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                            greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                            bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;



                            polygon1._polygon._material._color._value.red=redd;
                            polygon1._polygon._material._color._value.blue=bulee;
                            polygon1._polygon._material._color._value.green=greenn;
                            polygon1.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);
                            polygon2.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);


                            //point._point._color._value=color;
                            //console.log(position)
                            //譬如你可以在回调中把得到的 color 赋值给表单
                        }

                    })
                })
                // handlerdxmclick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                //console.log(pickedObject)
            }

        }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    handlerdxmclick.setInputAction(function () {
        pickedObject=null;
        handlerdxmclick.destroy(); //关闭事件句柄
        handlerdxmclick = null;
        console.log("关闭")
        $("#mianxxxx1").hide();
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}

function  xianji(){
    $("#dianxxxx1").hide();
    $("#dianxxxx").hide();
    $("#xianxxxx").hide();
    $("#xianxxxx1").hide();
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    pickedObject=null;
    var handlerdxmclick = new Cesium.ScreenSpaceEventHandler(canvas1);
    handlerdxmclick.setInputAction(function (event) {
        pickedObject = scene.pick(event.position);

        if (pickedObject && pickedObject.id) {
            //对对应的点的操作

            if(pickedObject.id._polyline!==null &&pickedObject.id._polygon==null){
                //pickedObject.id._label._text._value="22"
                //xianxxxx1

                xtd441.innerHTML= pickedObject.id._label._text._value;
                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#xysxz1',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                            redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                            greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                            bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                            pickedObject.id._polyline._material._color._value.red=redd;
                            pickedObject.id._polyline._material._color._value.blue=bulee;
                            pickedObject.id._polyline._material._color._value.green=greenn;

                        }

                    })
                })
                $("#xidbutton1").click(function(){

                    var value=$("#xidinput1").val();
                    if (value.length>0){

                        pickedObject.id._label._text._value=value;
                        xtd44.innerHTML =value;
                    }else {
                        alert("不能为空")
                    }

                })
            }
            $("#xianxxxx1").show();
            // handlerdxmclick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);

        }

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    handlerdxmclick.setInputAction(function () {
        pickedObject=null;
        handlerdxmclick.destroy(); //关闭事件句柄
        handlerdxmclick = null;
        console.log("关闭")
        $("#dianxxxx1").hide();
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}


function removeEntityByName(value) {
    // 清除之前的实体
    const entitys = viewer.entities._entities._array;
    let length = entitys.length
    // 倒叙遍历防止实体减少之后entitys[f]不存在
    for (let f = length - 1; f >= 0; f--) {
        if (entitys[f]._name && entitys[f]._name === value) {
            viewer.entities.remove(entitys[f]);
        }
    }
}
function ceshi(){
    // 单击折线时更改颜色
    $("#xianxxxx1").show();
    viewer.screenSpaceEventHandler.setInputAction(function(e) {
        var pickedObject = viewer.scene.pick(e.position);

        if (pickedObject && pickedObject.id) {
            // 更改选定折线的颜色
            layui.use('colorpicker', function () {
                var colorpicker = layui.colorpicker;
                //渲染
                var aa = colorpicker.render({
                    elem: '#xysxz1',  //绑定元素
                    format: 'rgb',
                    alpha: true,
                    done: function (color) {
                        redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                        greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                        bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                        pickedObject.id.polyline.material = new Cesium.Color(redd, greenn, bulee, 1);
                    }

                })
            })


        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

function dianji(change){
    $("#echartsView1").hide();
    $('#tishi').hide()


    // polyline=[];
    if (xianhandler!==null){
        xianhandler.destroy(); //关闭事件句柄
        xianhandler = null;
    }
    viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0);
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#dianxxxx1").hide();
    $("#dianxxxx").hide();
    $("#xianxxxx").hide();
    $("#xianxxxx1").hide();
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    pickedObject=null;
    var handlerdxmclick = new Cesium.ScreenSpaceEventHandler(canvas1);
    handlerdxmclick.setInputAction(function (event) {

        pickedObject = scene.pick(event.position);
        console.log(pickedObject)
        if (pickedObject && pickedObject.id) {
            //对对应的点的操作
            if (pickedObject.id._name=="点几何对象"){

                $("#dianxxxx").hide();
                $("#xianxxxx").hide();
                $("#xianxxxx1").hide();
                $("#mianxxxx").hide();
                $("#mianxxxx1").hide();
                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#ysxz1',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                           //  redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                           //  greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                           //  bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                           //  pickedObject.primitive._id._point._color._value.red=redd
                           //  pickedObject.primitive._id._point._color._value.blue=bulee
                           //  pickedObject.primitive._id._point._color._value.green=greenn
                           //  pickedObject.primitive._id._billboard._image._value="";
                           // pickedObject.primitive._id._point._color

                            pickedObject.id.point.color=Cesium.Color.fromCssColorString(color)
                            pickedObject.id.point.show=true;
                            pickedObject.id.billboard.width= 7;
                            pickedObject.id.billboard.height= 7;
                            pickedObject.id.point.pixelSize=7;
                            pickedObject.id.billboard.width=0
                            // pickedObject.primitive._id._point._pixelSize._value=7
                            // pickedObject.primitive._id._point._outlineWidth._value=0;


                        }

                    })
                })

                $("#ckj1").click(function(){
                    pickedObject.id.label.text="穿孔机"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/穿孔机.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="穿孔机"
                            td441.innerHTML=item.text
                        }
                    })
                    $("#ckj11").click(function(){
                        pickedObject.id.label.text="穿孔机"
                        pickedObject.id.point.pixelSize=0;
                        pickedObject.id.billboard.image="./images/穿孔机.png";
                        pickedObject.id.billboard.width= 50;
                        pickedObject.id.billboard.height= 50;
                        pickedObject.id.billboard.show._value=true;
                        TDdata_point.forEach((item,index)=>{
                            if (item.id==pickedObject.id._id){
                                item.text="穿孔机"
                                td441.innerHTML=item.text
                            }
                        })

                    })
                })

                $("#yjzd1").click(function(){
                    pickedObject.id.label.text="应急站点"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/yingjizhandian.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="应急站点"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#yljg1").click(function(){
                    pickedObject.id.label.text="医疗机构"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/yiliaojigou.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="医疗机构"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#dongtu1").click(function(){
                    pickedObject.id.label.text="动土"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/dongtu.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="动土"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#youdu1").click(function(){
                    pickedObject.id.label.text="有毒"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/youdu.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="有毒"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#yiran1").click(function(){
                    pickedObject.id.label.text="易燃"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/yiran.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="易燃"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#cheliang1").click(function(){
                    pickedObject.id.label.text="车辆"
                    pickedObject.id.point.pixelSize=0;
                    pickedObject.id.billboard.image="./images/cheliang.png";
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="车辆"
                            td441.innerHTML=item.text
                        }
                    })

                })

                $("#yuandian1").click(function(){
                    pickedObject.id.billboard.width= 7;
                    pickedObject.id.billboard.height= 7;
                    pickedObject.id.point.pixelSize=7;

                })
                $("#wzz1").click(function(){
                    pickedObject.id.label.text="摄像头";
                    pickedObject.id.billboard.image="./images/shexiangtou.png";
                    pickedObject.id.point.pixelSize=0
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                           item.text="摄像头"
                            td441.innerHTML=item.text
                        }
                    })
                    console.log(pickedObject)
                })

                $("#wzz11").click(function(){
                    pickedObject.id.label.text="摄像头";
                    pickedObject.id.billboard.image="./images/shexiangtou.png";
                    pickedObject.id.point.pixelSize=0
                    pickedObject.id.billboard.width= 50;
                    pickedObject.id.billboard.height= 50;
                    pickedObject.id.billboard.show._value=true;
                    TDdata_point.forEach((item,index)=>{
                        if (item.id==pickedObject.id._id){
                            item.text="摄像头"
                            td441.innerHTML=item.text
                        }
                    })
                    console.log(pickedObject)
                })

                $("#idbutton1").click(function(){
                    var value=$("#idinput1").val();
                    if (value.length>0){
                        pickedObject.id._label._text._value=value;
                        td441.innerHTML =value;

                    }else{
                        alert("不能为空")
                    }

                })

                var td441_value
                var td111_value
                var td221_value
                var td331_value

                console.log('TDdata_point',TDdata_point)
                TDdata_point.forEach((item,index)=>{
                    if (item.id==pickedObject.id._id){
                        td441_value=item.text
                        td111_value=item.lng;
                        td221_value=item.lat;
                        td331_value=item.height
                    }
                })


                td441.innerHTML = td441_value
                td111.innerHTML = td111_value
                td221.innerHTML = td221_value
                td331.innerHTML = td331_value
                $("#dianxxxx1").show();
            }
            else if(pickedObject.id._polyline!==null &&pickedObject.id._polygon==null){


                $("#dianxxxx1").hide();
                $("#dianxxxx").hide();
                $("#xianxxxx").hide();
                $("#mianxxxx").hide();
                $("#mianxxxx1").hide();

                xtd441.innerHTML= pickedObject.id._label._text._value;

                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#xysxz1',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                            $('#xiancolorPicker').css('background-color', color);
                            redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                            greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                            bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                            pickedObject.id.polyline.material.color =new Cesium.Color(redd, greenn, bulee, 1);
                        }

                    })
                })
                $("#shixian_button").click(function (){

                   // pickedObject.id.polyline.material.color
                })

                $("#xidbutton1").click(function(){

                    var value=$("#xidinput1").val();
                    if (value.length>0){

                        pickedObject.id._label._text._value=value;
                        xtd44.innerHTML =value;
                    }else {
                        alert("不能为空")
                    }

                })
                console.log(pickedObject.id.polyline.material)

                var material = pickedObject.id.polyline.material;

                // if (material.hasOwnProperty('_dashPattern')) {
                //     // 如果存在 _dashPattern 属性，则处理虚线逻辑
                //     // 例如：设置虚线的样式、间隔等
                //      console.log("这是虚线");
                //     // $("#xianname").text("虚线")
                //     $("#xianname").text("445454")
                //
                // } else {
                //     // 如果不存在 _dashPattern 属性，则处理实线逻辑
                //     console.log("这是实线");
                //     $("#xianname").text("实线")
                // }

                var color = pickedObject.id.polyline.material.color._value;
                // 计算 rgba() 格式的颜色值
                var rgbaColor = 'rgba(' + Math.round(color.red * 255) + ',' + Math.round(color.green * 255) + ',' + Math.round(color.blue * 255) + ',' + color.alpha + ')';
                // 使用 jQuery 设置 div 元素的背景色
                $('#xiancolorPicker').css('background-color', rgbaColor);
                // var xiannametext=$("#xian1name").text()
                // $("#xianname").text(xiannametext)
                $("#shixian2_button").click(function (){
                    $("#xianname").text("实线")
                    var xcolor=  pickedObject.id.polyline.material.color._value;
                    pickedObject.id.polyline.material=new Cesium.Color(xcolor.red, xcolor.blue, xcolor.green, 1);

                })
                $("#xuxian2_button").click(function (){
                    $("#xianname").text("虚线")
                    var xcolor=  pickedObject.id.polyline.material.color._value;
                    pickedObject.id.polyline.material=new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color(xcolor.red, xcolor.blue, xcolor.green, 1),
                    })

                })

                if (material.hasOwnProperty('_dashPattern')) {
                    // 如果存在 _dashPattern 属性，则处理虚线逻辑
                    // 例如：设置虚线的样式、间隔等
                    console.log("这是虚线");
                    $("#xianname").text("虚线")
                    // $("#xianname").text("445454")

                } else {
                    // 如果不存在 _dashPattern 属性，则处理实线逻辑
                    console.log("这是实线");
                    $("#xianname").text("实线")
                }

            $("#xianxxxx1").show();
            // handlerdxmclick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
            //console.log(pickedObject)
            }
            else {
                //pickedObject.id._label._text._value="22"
                //xianxxxx1
                $("#dianxxxx1").hide();
                $("#dianxxxx").hide();
                $("#xianxxxx").hide();
                $("#xianxxxx1").hide();
                $("#mianxxxx").hide();
                 if (pickedObject.id._polygon._material._image){
                     $("#mianimg_cbl1").attr("src", pickedObject.id._polygon._material._image._value);
                 }else {
                     $("#mianimg_cbl1").attr("src", "");
                 }

                var color = pickedObject.id._polygon._material._color._value;
                // 计算 rgba() 格式的颜色值
                var rgbaColor = 'rgba(' + Math.round(color.red * 255) + ',' + Math.round(color.green * 255) + ',' + Math.round(color.blue * 255) + ',' + color.alpha + ')';
                // 使用 jQuery 设置 div 元素的背景色
                $('#miancolor_cbl1').css('background-color', rgbaColor);

                 console.log(pickedObject.id._polygon)

                $("#midbutton1").click(function(){
                    var value=$("#midinput1").val();

                    if (value.length>0){
                        pickedObject.id._label._text._value=value;
                        mtd441.innerHTML =value;

                    }else {
                        alert("不能为空")
                    }

                })
                $('#2tianchong1').click(function (){

                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/qipan.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/qipan.png");
                })

                $('#2tianchong2').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/taiowen.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/taiowen.png");
                })

                $('#2tianchong3').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/网格.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/网格.png");
                })
                $('#2tianchong4').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/编织物.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/编织物.png");
                })
                $('#2tianchong5').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/纸袋.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/纸袋.png");
                })
                $('#2tianchong6').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/草纸.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/草纸.png");
                })
                $('#2tianchong7').click(function (){
                    //完整的这么写
                    // pickedObject.id.polygon.material = new Cesium.GridMaterialProperty({
                    //     color : Cesium.Color.YELLOW,
                    //     cellAlpha : 0.2,
                    //     lineCount : new Cesium.Cartesian2(8, 8),
                    //     lineThickness : new Cesium.Cartesian2(2.0, 2.0)
                    // });
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/浅色横线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/浅色横线.png");
                })
                $('#2tianchong8').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/浅色竖线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/浅色竖线.png");
                })
                $('#2tianchong9').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/宽下对角线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "宽下对角线.png");
                })
                $('#2tianchong10').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/qipan.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/qipan.png");
                })
                $('#2tianchong11').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/taiowen.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl1").attr("src", "images/taiowen.png");
                })


                mtd441.innerHTML= pickedObject.id._label._text._value;
                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#mysxz1',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                            redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                            greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                            bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                            // pickedObject.id._polygon._material._color._value.red=redd;
                            // pickedObject.id._polygon._material._color._value.blue=bulee;
                            // pickedObject.id._polygon._material._color._value.green=greenn;
                           // pickedObject.id.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);
                            pickedObject.id.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);
                            $("#miancolor_cbl1").css("background-color",color)

                            //point._point._color._value=color;
                            //console.log(position)
                            //譬如你可以在回调中把得到的 color 赋值给表单
                        }

                    })
                })
                // handlerdxmclick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                //console.log(pickedObject)
                $("#mianxxxx1").show();
            }
        }

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    handlerdxmclick.setInputAction(function () {
        pickedObject=null;
        handlerdxmclick.destroy(); //关闭事件句柄
        handlerdxmclick = null;
        console.log("关闭")
        $("#dianxxxx1").hide();
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);



}


var numb = 0;
var list=[];
function adddian() {
    //dianhandler.destroy(); //关闭事件句柄
    //dianhandler = null;
    $('#tishi').show()
    $("#echartsView1").hide();
    $("#xianxxxx1").hide();
    $("#dianxxxx1").hide();

    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    $("#moxing").hide();
    $("#moxing1").hide();
    $("#xianxxxx").hide();

    for(var i=0;i<=swzbid.length;i++){
        viewer.entities.removeById(swzbid[i]);

    }
    var body = document.querySelector("body");
    body.style.cursor = "crosshair";
    //viewer.scene.globe.depthTestAgainstTerrain = true;

     dianhandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    // 监听鼠标左键
    dianhandler.setInputAction(function(event) {
        //var cartesian = viewer.scene.pickPosition(event.position);
        var cartesian = getCatesian3FromPX1(event.position);
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var lng = Cesium.Math.toDegrees(cartographic.longitude);
        var lat = Cesium.Math.toDegrees(cartographic.latitude);
        var height = cartographic.height; //模型高度

        // 从相机位置通过windowPosition 世界坐标中的像素创建一条射线。返回Cartesian3射线的位置和方向。
        let ray = viewer.camera.getPickRay(event.position);
        // 查找射线与渲染的地球表面之间的交点。射线必须以世界坐标给出。返回Cartesian3对象
        let position = viewer.scene.globe.pick(ray, viewer.scene);

        point = viewer.entities.add({
            name: "点几何对象",
            id: numb += 1,
            position: cartesian,
            label: {
                text: `${numb}`,
                font: '20px sans-serif', // 字体大小
                style: Cesium.LabelStyle.FILL_AND_OUTLINE, // 字体样式
                fillColor: new Cesium.Color.fromCssColorString("#F41608"), // 字体填充色
                outlineWidth: 1,  // 字体外圈线宽度（同样也有颜色可设置）
                outlineColor: new Cesium.Color.fromCssColorString("#ffffff"),
                verticalOrigin: Cesium.VerticalOrigin.TOP, // 垂直位置
                pixelOffset: new Cesium.Cartesian2(0, 15),  // 中心位置
                clampToGround:true,  //是否贴地，
                heightReference:Cesium.HeightReference.CLAMP_TO_GROUND,
                disableDepthTestDistance:99000000,
            },
            billboard: { //图标
                image: './images/穿孔机.png',//./images/shexiangtou.png
                width: 50,
                height: 50,
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                //heightReference: Cesium.HeightReference.NONE
                heightReference :Cesium.HeightReference.NONE, // 高度参考为贴地
                clampToGround:true,  //是否贴地
                show:false
            },

            point: {
                    color: new Cesium.Color.fromCssColorString("#F41608"), //Cesium.Color.fromBytes(186, 186, 57)
                    pixelSize: 7,
                    clampToGround:true, //是否贴地
                    disableDepthTestDistance:99000000,

            }
            //选中点  弹出选择图标界面，直接选择对应图标 进行修改 然后有一个关闭逻辑（关闭当前选中事件）

        });
        layui.use('colorpicker', function () {
            var colorpicker = layui.colorpicker;
            //渲染
            var aa = colorpicker.render({
                elem: '#ysxz',  //绑定元素
                format: 'rgb',
                alpha: true,
                done: function (color) {

                    // redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                    // greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                    // bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                    // point._point._color._value.red=redd
                    // point._point._color._value.blue=bulee
                    // point._point._color._value.green=greenn
                    point.point.show=true;
                    point.billboard.width= 7;
                    point.billboard.height= 7;
                    point.point.pixelSize=7;
                    point.point.color=Cesium.Color.fromCssColorString(color)
                    //point.billboard.width= 0;



                 //point._point._color._value=color;
                 //console.log(point._point._color._value)
                    //譬如你可以在回调中把得到的 color 赋值给表单
                }

            })
        })
        $("#ckj").click(function(){
            point.billboard.show=true;
            point.label.text="穿孔机"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/穿孔机.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="穿孔机"
        })
        $("#ckj01").click(function(){
            point.billboard.show=true;
            point.label.text="穿孔机"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/穿孔机.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="穿孔机"
        })
        $("#yjzd").click(function(){
            point.billboard.show=true;
            point.label.text="应急站点"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/yingjizhandian.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="应急站点"
        })
        $("#yljg").click(function(){
            point.billboard.show=true;
            point.label.text="医疗机构"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/yiliaojigou.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="医疗机构"
        })
        $("#dongtu").click(function(){
            point.billboard.show=true;
            point.label.text="动土"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/dongtu.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="动土"
        })
        $("#youdu").click(function(){
            point.billboard.show=true;
            point.label.text="有毒"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/youdu.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="有毒"
        })
        $("#yiran").click(function(){
            point.billboard.show=true;
            point.label.text="易燃"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/yiran.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="易燃"
        })
        $("#cheliang").click(function(){
            point.billboard.show=true;
            point.label.text="车辆定位"
            point.point.pixelSize=50
            point.point.show=false;
            // point._label._text._value="穿孔机";
            point.billboard.image="./images/车辆定位.png";
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="车辆定位"
        })
        $("#wzz").click(function(){
            point.billboard.show=true;
            point.label.text="摄像头";
            point.point.show=false;
            point.billboard.image="./images/shexiangtou.png";
            point.point.pixelSize=50
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="摄像头"
        })
        $("#wzz01").click(function(){
            point.billboard.show=true;
            point.label.text="摄像头";
            point.point.show=false;
            point.billboard.image="./images/shexiangtou.png";
            point.point.pixelSize=50
            point.billboard.width= 50;
            point.billboard.height= 50;
            TDdata_point[TDdata_point.length-1].text="摄像头"
        })
        $("#yuandian").click(function(){
            point.point.show=true;
            point.billboard.width= 7;
            point.billboard.height= 7;
            point.point.pixelSize=7;


        })
        $("#idbutton").click(function(){
            var value=$("#idinput").val();
            if (value.length>0){
                point._label._text._value=value;
                TDdata_point[TDdata_point.length-1].text=value
                td44.innerHTML =value;
            }else{
                alert("不能为空")
            }

        })
        list.push(numb);



        td44.innerHTML = point._id;
        td11.innerHTML = lng.toFixed(9);
        td22.innerHTML = lat.toFixed(9);
        td33.innerHTML =height.toFixed(4) ;
        var json_point={
            'id': point._id,
            'text':td44.innerHTML,
            'lng': lng.toFixed(9),
            'lat':lat.toFixed(9),
            'height':height.toFixed(4)
        }
        TDdata_point.push(json_point)
        $("#dianxxxx").show();
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // 右击单击停止绘制
    dianhandler.setInputAction(function(event) {
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
        viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        //var body=document.querySelector("body");
        body.style.cursor = "default";
        $("#bianji").show();
        $("#dianxxxx").hide();
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}

function getCatesian3FromPX1(px) {

    if (this._viewer && px) {
        var picks = this._viewer.scene.drillPick(px)
        var cartesian = null;
        var isOn3dtiles = false,
            isOnTerrain = false;
        // drillPick
        for (let i in picks) {
            let pick = picks[i]

            if (pick &&
                pick.primitive instanceof Cesium.Cesium3DTileFeature ||
                pick && pick.primitive instanceof Cesium.Cesium3DTileset ||
                pick && pick.primitive instanceof Cesium.Model) { //模型上拾取
                isOn3dtiles = true;
            }
            // 3dtilset
            if (isOn3dtiles) {
                this._viewer.scene.pick(px) // pick
                cartesian = this._viewer.scene.pickPosition(px);
                if (cartesian) {
                    let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    if (cartographic.height < 0) cartographic.height = 0;
                    let lon = Cesium.Math.toDegrees(cartographic.longitude),
                        lat = Cesium.Math.toDegrees(cartographic.latitude),
                        height = cartographic.height;
                    cartesian = this.transformWGS84ToCartesian({
                        lng: lon,
                        lat: lat,
                        alt: height
                    })

                }
            }
        }
        // 地形
        let boolTerrain = this._viewer.terrainProvider instanceof Cesium
            .EllipsoidTerrainProvider;
        // Terrain
        if (!isOn3dtiles && !boolTerrain) {
            var ray = this._viewer.scene.camera.getPickRay(px);
            if (!ray) return null;
            cartesian = this._viewer.scene.globe.pick(ray, this._viewer.scene);
            isOnTerrain = true
        }
        // 地球
        if (!isOn3dtiles && !isOnTerrain && boolTerrain) {

            cartesian = this._viewer.scene.camera.pickEllipsoid(px, this._viewer.scene.globe
                .ellipsoid);
        }
        if (cartesian) {
            let position = transformCartesianToWGS84(cartesian)
            if (position.alt < 0) {
                cartesian = transformWGS84ToCartesian(position, 0.1)
            }
            return cartesian;
        }
        return false;
    }

}

/***
 * 坐标转换 84转笛卡尔
 *
 * @param {Object} {lng,lat,alt} 地理坐标
 *
 * @return {Object} Cartesian3 三维位置坐标
 */
function transformWGS84ToCartesian (position, alt) {
    if (this._viewer) {
        return position ?
            Cesium.Cartesian3.fromDegrees(
                position.lng || position.lon,
                position.lat,
                position.alt = alt || position.alt,
                Cesium.Ellipsoid.WGS84
            ) :
            Cesium.Cartesian3.ZERO
    }
}

/***
 * 坐标转换 笛卡尔转84
 *
 * @param {Object} Cartesian3 三维位置坐标
 *
 * @return {Object} {lng,lat,alt} 地理坐标
 */
 function transformCartesianToWGS84(cartesian) {
    if (this._viewer && cartesian) {
        var ellipsoid = Cesium.Ellipsoid.WGS84
        var cartographic = ellipsoid.cartesianToCartographic(cartesian)
        return {
            lng: Cesium.Math.toDegrees(cartographic.longitude),
            lat: Cesium.Math.toDegrees(cartographic.latitude),
            alt: cartographic.height
        }
    }
}
var xianid=0;
function addxian() {
    $('#tishi').show()

    $("#echartsView1").hide();
    xianhandler=null;
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    $("#dianxxxx1").hide();
    xianid+=1;
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#mianxxxx").hide();
    $("#mianxxxx1").hide();
    $("#dianxxxx").hide();
    $("#xianxxxx").hide();
    $("#xianxxxx1").hide();
    $("#moxing").hide();
    $("#moxing1").hide();

    for(var i=0;i<=swzbid.length;i++){
        viewer.entities.removeById(swzbid[i]);

    }
    var body = document.querySelector("body");
    body.style.cursor = "crosshair";
    viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

    //viewer.scene.globe.depthTestAgainstTerrain = true;
     xianhandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

    let tempPoints = [];
    let _mousePos = null; //移动点
    //左键点击操作
    xianhandler.setInputAction((e) => {
        var cartesian = getCatesian3FromPX1(e.position);
        let ray = viewer.camera.getPickRay(e.position);
        let position = viewer.scene.globe.pick(ray, viewer.scene);
        tempPoints.push(cartesian);
        //调用绘制点的接口


        polyline1=viewer.entities.add({
            name: xianid+"线几何对象",
            polyline: {
                positions: new Cesium.CallbackProperty(() => {
                    let c = Array.from(tempPoints);
                    if (_mousePos) {
                        c.push(_mousePos);
                    }
                    return c;
                }, false),
                width: 3.0,
                material: new Cesium.PolylineDashMaterialProperty({
                    color: new Cesium.Color.fromCssColorString("#FD0803"),
                }),
                // depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                //     color: new Cesium.Color.fromCssColorString("#FD0803"),
                // }),

                clampToGround: true,
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            },
        });
        //console.log("addxian",point)
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    xianhandler.setInputAction((e) => {
        let p = viewer.scene.pickPosition(e.endPosition);
        if (!p) return;
        _mousePos = p;
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);



    //右键点击操作
    xianhandler.setInputAction((e) => {

        polyline=viewer.entities.add({
            polyline: {
                id:xianid,
                name:xianid+ "线几何对象",
                positions: tempPoints,
                clampToGround: true, //贴地
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                width: 3,
                material: new Cesium.PolylineDashMaterialProperty({
                    color: new Cesium.Color.fromCssColorString("#FD0803"),
                }),
                // depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                //     color: new Cesium.Color.fromCssColorString("#FD0803"),
                // }),

            },



        });



        var summx=0;
        var summy=0;
        var summz=0;
        for (var i=0;i< tempPoints.length;i++){

            summx+=tempPoints[i].x ;
            summy+=tempPoints[i].y ;
            summz+=tempPoints[i].z ;
        }

        var position =  {x:summx/tempPoints.length,y:summy/tempPoints.length,z:summz/tempPoints.length}
        polyline.position=position;
        polyline.polyline.id=xianid;
        polyline.polyline.name=xianid+ "线几何对象"
        polyline. label= {
            // position:
            text:`${xianid}号线段`,
            color : Cesium.Color.fromCssColorString('#E73C18'),
            font:'normal 32px MicroSoft YaHei',
            showBackground : true,
            scale : 0.5,
            horizontalOrigin : Cesium.HorizontalOrigin.LEFT_CLICK,
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
            disableDepthTestDistance : 100000.0

        }


        $("#xian1name").text("虚线")
        $("#xianxxxx").show();
        $("#xidbutton").click(function(){

            var value=$("#xidinput").val();
            if (value.length>0){
                polyline. label.text._value=value;
                xtd44.innerHTML =value;
            }else {
                alert("不能为空")
            }

        })
        $("#shixian_button").click(function (){
            $("#xian1name").text("实线")
            var xcolor=polyline.polyline.material.color._value;
            polyline.polyline.material=new Cesium.Color(xcolor.red, xcolor.blue, xcolor.green, 1);

        })
        $("#xuxian_button").click(function (){
            $("#xian1name").text("虚线")
            var xcolor=polyline.polyline.material.color._value;
            polyline.polyline.material=new Cesium.PolylineDashMaterialProperty({
                    color: new Cesium.Color(xcolor.red, xcolor.blue, xcolor.green, 1),
                })

        })
        xtd44.innerHTML=xianid+"号线段";
        layui.use('colorpicker', function () {
            var colorpicker = layui.colorpicker;
            //渲染
            var aa = colorpicker.render({
                elem: '#xysxz',  //绑定元素
                format: 'rgb',
                alpha: true,
                done: function (color) {
                    $('#xian1colorPicker').css('background-color', color);
                    redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                    greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                    bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                    polyline.polyline._material._color._value.red=redd;
                    polyline.polyline._material._color._value.blue=bulee;
                    polyline.polyline._material._color._value.green=greenn;
                    polyline.polyline.depthFailMaterial=new Cesium.Color(redd, greenn, bulee, 0.5);

                }

            })
        })
        // polyline.polyline._material._color._value.red=1;
        // polyline.polyline._material._color._value.blue=1;
        // polyline.polyline._material._color._value.green=0;
        tempPoints = [];
        xianhandler.destroy(); //关闭事件句柄
        xianhandler = null;
        body.style.cursor = "default";
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

}



var mianid=0;
// 点击创建面实体
function draw1() {
    $("#dianxxxx1").hide();
    mianid+=1;
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#mianxxxx").hide();
    $("#xianxxxx").hide();
    $("#dianxxxx").hide();
    $("#moxing").hide();
    $("#moxing1").hide();

    for(var i=0;i<=swzbid.length;i++){
        viewer.entities.removeById(swzbid[i]);

    }
    let addPolygon = []; // 记录绘制过程中的面实体
    const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
    let movePosition = []; // 记录绘制过程中移动的点位置
    let moveEntity = null; // 记录绘制过程中移动的点实体
    let positions = []; // 记录左键点击的点位置
    let polygonEntity = null; // 记录面实体
    let pointEntities = []; // 记录左键点击的点实体

    // 鼠标移动事件
    handler.setInputAction(event => {
        // 除第一次，每次移动都会删除上次的点实体
        moveEntity && viewer.entities.remove(moveEntity);
        // 每次移动，都会删除上次的移动点位置，置为空数组
        movePosition = [];
        // 每次移动都会记录当前点位置
        movePosition.push(changeToThree(event.endPosition));
        // 创建移动点实体
        viewer.entities.add({
            position: movePosition[0],
            point: {
                pixelSize: 8,
                color: Cesium.Color.fromCssColorString('red').withAlpha(0.7),
            },
        });
        // 记录点实体
        moveEntity = viewer.entities.values.slice(-1)[0];
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    // 点击左键事件
    handler.setInputAction(event => {
        // 记录左键点击的点实体位置
        positions.push(changeToThree(event.position));
        // 如果左键已经点击产生了一个点，加上移动的点，已经能够构成一个线段了
        if (positions.length === 1) {
            // 添加绘制的面实体
            polygonEntity = viewer.entities.add({
                polygon: {
                    // 绘制动态面实体时，面的位置信息必须是使用 Cesium.CallbackProperty() 和 Cesium.PolygonHierarchy() 返回的坐标
                    hierarchy: new Cesium.CallbackProperty(function() {
                        return new Cesium.PolygonHierarchy(positions.concat(movePosition));
                    }, false),
                    material: Cesium.Color.fromCssColorString('red').withAlpha(0.7),
                },
                polyline: {
                    positions: new Cesium.CallbackProperty(function() {
                        return positions.concat(movePosition).concat([positions[0]]);
                    }, false),
                    material: Cesium.Color.fromCssColorString('blue').withAlpha(0.5),
                    // 必须给 golyline 设置贴地，否则会造成绘制的面和线在地图放大到一定程度后有误差
                    clampToGround: true,
                    width: 3,
                },
            });
        }
        // 添加点实体
        viewer.entities.add({
            position: changeToThree(event.position),
            point: {
                pixelSize: 8,
                color: Cesium.Color.fromCssColorString('red').withAlpha(0.7),
            },
        });
        // 记录点实体
        pointEntities.push(viewer.entities.values.slice(-1)[0]);
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    // 点击右键事件
    handler.setInputAction(() => {
        // 删除所有的点实体
        pointEntities.forEach(item => {
            viewer.entities.remove(item);
        });
        // 必须大于等于 3 个点才能创建面，否则删除
        if (positions.length >= 3) {
            addPolygon.push(polygonEntity);
            // 将最终的面信息保存起来,为了将面的位置信息保存起来
            polygonEntity.polygon.hierarchy = positions;
            // // 计算面实体的面积和周长
            // const polygon = turf.polygon([changeToLnglgt(positions.concat(positions[0]))]);
            // const S = turf.area(polygon);
            // const lineString = turf.lineString(changeToLnglgt(positions.concat(positions[0])));
            // const C = turf.length(lineString);
            // console.log(`该面实体的面积为${ S / 1000000 }km^2, 该面实体的周长为${ C }km`)
        } else {
            viewer.entities.remove(polygonEntity);
        };
        // 记录添加的面实体
        addPolygon.push(polygonEntity);
        movePosition = []; // 控制最后右键点击的点是否保留
        // 删除最后一个移动的点实体
        viewer.entities.remove(moveEntity);

        // 取消所有的监听函数
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
        handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        polygonEntity.label={
            // position:
            text:`${mianid}号面`,
                color : Cesium.Color.fromCssColorString('#E73C18'),
                font:'normal 32px MicroSoft YaHei',
                showBackground : true,
                scale : 0.5,
                horizontalOrigin : Cesium.HorizontalOrigin.LEFT_CLICK,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                disableDepthTestDistance : 100000.0



        }

    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
};

// 点击删除所有的面实体
function clearAll() {
    addPolygon.forEach(item => {
        viewer.entities.remove(item);
    });
};

// 定义一个将经纬度格式转为世界坐标格式的方法
function changeToThree(position) {
    if (!position) return [];
    return viewer.scene.globe.pick(viewer.camera.getPickRay(position), viewer.scene);
}

// 定义 CGCS2000 投影坐标转换函数
function convertToProjection(latitude, longitude) {
    // 投影中央经度
    const centralMeridian = 105.0;
    // 经度偏移量
    const xOffset = 500000.0;
    // 纬度偏移量
    const yOffset = 0.0;
    // 椭球体半长轴
    const a = 6378137.0;
    // 椭球体偏率平方
    const e2 = 0.00669438002301188;

    // 弧度转换
    const radLat = latitude * Math.PI / 180.0;
    const radLon = longitude * Math.PI / 180.0;
    const radCentralMeridian = centralMeridian * Math.PI / 180.0;

    // 计算子午线弧长
    const A = a / Math.sqrt(1 - e2 * Math.sin(radLat) * Math.sin(radLat));
    const B = Math.tan(radLat) * Math.tan(radLat);
    const C = e2 * Math.cos(radLat) * Math.cos(radLat);
    const D = (radLon - radCentralMeridian) * Math.cos(radLat);
    const E = Math.sqrt(1 - e2 * Math.sin(radLat) * Math.sin(radLat));

    const M = a * ((1 - e2 / 4 - 3 * e2 * e2 / 64 - 5 * e2 * e2 * e2 / 256) * radLat -
        (3 * e2 / 8 + 3 * e2 * e2 / 32 + 45 * e2 * e2 * e2 / 1024) * Math.sin(2 * radLat) +
        (15 * e2 * e2 / 256 + 45 * e2 * e2 * e2 / 1024) * Math.sin(4 * radLat) -
        (35 * e2 * e2 * e2 / 3072) * Math.sin(6 * radLat));

    // 计算投影坐标
    const x = xOffset + A * (D + (1 - B + C) * D * D * D / 6 + (5 - 18 * B + B * B + 72 * C - 58 * e2) * D * D * D * D * D / 120);
    const y = yOffset + M + A * Math.tan(radLat) * (D * D / 2 + (5 - B + 9 * C + 4 * C * C) * D * D * D * D / 24 +
        (61 - 58 * B + B * B + 600 * C - 330 * e2) * D * D * D * D * D * D / 720);

    return { x, y };
}




console.log("=======")

function addmian_cbl() {
    cbllist=[];
    let handler_cbl = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    let tempPoints = [];
    let _mousePos = null;
    var body = document.querySelector("body");
    body.style.cursor = "crosshair";
    //左键点击操作
    handler_cbl.setInputAction(function(click) {
        //调用获取位置信息的接口
        var cartesian = getCatesian3FromPX1(click.position);
        let ray = viewer.camera.getPickRay(click.position);
        let position = viewer.scene.globe.pick(ray, viewer.scene);
        let cartographic = Cesium.Cartographic.fromCartesian(cartesian);

        var lon = Cesium.Math.toDegrees(cartographic.longitude);
        var lat = Cesium.Math.toDegrees(cartographic.latitude);
        const projection = convertToProjection(lat, lon);
        console.log('投影坐标：', projection);

          // 将经纬度转换为2000坐标系下的投影坐标
        // var projected = Cesium.GeoConverter.WGS84ToCGCS2000(lon, lat);

        var datacbl=start(Cesium.Math.toDegrees(cartographic.longitude),Cesium.Math.toDegrees(cartographic.latitude))
        // var datacbl=wgs_2000(Cesium.Math.toDegrees(cartographic.longitude),Cesium.Math.toDegrees(cartographic.latitude))

        console.log("===============")
        // console.log(start(119.1221,45.9335,))
        // console.log(projected)

        cbllist.push({x:datacbl[1],y:datacbl[0],z:cartographic.height})
        tempPoints.push(cartesian);
        if (tempPoints.length == 1) {
            viewer.entities.add({
                name: "线几何对象",
                polyline: {
                    positions: new Cesium.CallbackProperty(() => {
                        let c = Array.from(tempPoints);
                        if (_mousePos) {
                            c.push(_mousePos);
                        }
                        return c;
                    }, false),
                    clampToGround: true, //贴地
                    width: 1,
                    material: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                    depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                },
            });
        } else {
            //viewer.entities.removeAll();
            polygon2=viewer.entities.add({
                polygon: {
                    hierarchy: new Cesium.CallbackProperty(() => {
                        let poss = Array.from(tempPoints);
                        if (_mousePos) {
                            poss.push(_mousePos);
                        }
                        return new Cesium.PolygonHierarchy(poss);
                    }, false),

                    extrudedHeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    material: new Cesium.Color.fromCssColorString("#FD1B03").withAlpha(0.8),
                    //clampToGround: true,
                },
                polyline: {
                    positions: new Cesium.CallbackProperty(() => {
                        let c = Array.from(tempPoints);
                        if (_mousePos) {
                            c.push(_mousePos);
                            c.push(c[0]); //与第一个点相连
                        }
                        return c;
                    }, false),
                    clampToGround: true, //贴地
                    width: 2,
                    material: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                    depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                },
            });
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    //右键点击操作
    handler_cbl.setInputAction(function(click) {
        let cartesian = viewer.camera.pickEllipsoid(
            click.position,
            viewer.scene.globe.ellipsoid
        );

        if (cartesian) {
            let tempLength = tempPoints.length;
            if (tempLength < 3) {
                alert("请选择3个以上的点再执行闭合操作命令");
            } else {
                //viewer.entities.removeAll();

                polygon1=viewer.entities.add({
                    polyline: {

                        positions: new Cesium.CallbackProperty(() => {
                            let c = Array.from(tempPoints);
                            c.push(c[0]);
                            return c;
                        }, false),
                        clampToGround: true, //贴地
                        width: 2,
                        material: new Cesium.PolylineDashMaterialProperty({
                            color: new Cesium.Color.fromCssColorString("#FDE703"),
                        }),
                        depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                            color: new Cesium.Color.fromCssColorString("#FDE703"),
                        }),
                    },
                    polygon: {
                        name: "面几何对象",
                        hierarchy: tempPoints,
                        extrudedHeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                        material: new Cesium.Color.fromCssColorString("#FD1B03").withAlpha(1),
                        clampToGround: true,

                    },


                });
                handler_cbl.destroy(); //关闭事件句柄
                handler_cbl = null;
                body.style.cursor = "default";
            }
        }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

    // cbllist=tempPoints
    console.log("===============")
    console.log(cbllist)
}
function addxian_yjps() {
    var xiancblhandler=null;
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    var body = document.querySelector("body");
    body.style.cursor = "crosshair";
    viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
    //viewer.scene.globe.depthTestAgainstTerrain = true;
    xiancblhandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    let tempPoints = [];
    tempPoints_cbl = [];
    let _mousePos = null; //移动点
    //左键点击操作
    xiancblhandler.setInputAction((e) => {
        var cartesian = getCatesian3FromPX1(e.position);
        let ray = viewer.camera.getPickRay(e.position);
        let position = viewer.scene.globe.pick(ray, viewer.scene);

        let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var datacbl=start(Cesium.Math.toDegrees(cartographic.longitude),Cesium.Math.toDegrees(cartographic.latitude))

        tempPoints_cbl.push({x:datacbl[0],y:datacbl[1],z:cartographic.height})

        tempPoints.push(cartesian)

        //调用绘制点的接口
        viewer.entities.add({
            name: xianid+"线几何对象",
            polyline: {
                positions: new Cesium.CallbackProperty(() => {
                    let c = Array.from(tempPoints);
                    if (_mousePos) {
                        c.push(_mousePos);
                    }
                    return c;
                }, false),
                width: 3.0,
                material: new Cesium.PolylineDashMaterialProperty({
                    color: new Cesium.Color.fromCssColorString("#FD0803"),
                }),
                // depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                //     color: new Cesium.Color.fromCssColorString("#FD0803"),
                // }),

                clampToGround: true,
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                //heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            },
        });
        //console.log("addxian",point)
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    xiancblhandler.setInputAction((e) => {
        let p = viewer.scene.pickPosition(e.endPosition);
        if (!p) return;
        _mousePos = p;
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    //右键点击操作
    xiancblhandler.setInputAction((e) => {
        var cartesian = getCatesian3FromPX1(e.position);
        let ray = viewer.camera.getPickRay(e.position);
        let position = viewer.scene.globe.pick(ray, viewer.scene);
        let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var datacbl=start(Cesium.Math.toDegrees(cartographic.longitude),Cesium.Math.toDegrees(cartographic.latitude))

        tempPoints_cbl.push({x:datacbl[0],y:datacbl[1],z:cartographic.height})
        // tempPoints.push(cartesian);
        viewer.entities.add({
            polyline: {
                id:xianid,
                name:xianid+ "线几何对象",
                positions: tempPoints,
                clampToGround: true, //贴地
                disableDepthTestDistance: Number.POSITIVE_INFINITY,
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                width: 3,
                material: new Cesium.PolylineDashMaterialProperty({
                    color: new Cesium.Color.fromCssColorString("#FD0803"),
                }),
            },
        });
        xiancblhandler.destroy(); //关闭事件句柄
        xiancblhandler = null;
        body.style.cursor = "default";
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);


    // console.log(tempPoints_cbl)
    return tempPoints_cbl;
}

function addmian() {
    $("#mianimg_cbl").attr("src", "");
    $('#tishi').show()
    $("#echartsView1").hide();
    $("#dianxxxx1").hide();
    $("#xianxxxx1").hide();
    $("#mianxxxx1").hide();
    mianid+=1;
    if (dianhandler!==null){
        dianhandler.destroy(); //关闭事件句柄
        dianhandler = null;
    }
    if (handler22!==null){
        handler22.destroy(); //关闭事件句柄
        handler22 = null;
    }
    $("#mianxxxx").hide();
    $("#xianxxxx").hide();
    $("#dianxxxx").hide();
    $("#moxing").hide();
    $("#moxing1").hide();

    for(var i=0;i<=swzbid.length;i++){
        viewer.entities.removeById(swzbid[i]);

    }
    var body = document.querySelector("body");
    body.style.cursor = "crosshair";
    //viewer.scene.globe.depthTestAgainstTerrain = true;
    let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

    let tempPoints = [];
    let _mousePos = null;
    //左键点击操作
    handler.setInputAction(function(click) {
        //调用获取位置信息的接口
        var cartesian = getCatesian3FromPX1(click.position);
        let ray = viewer.camera.getPickRay(click.position);
        let position = viewer.scene.globe.pick(ray, viewer.scene);
        tempPoints.push(cartesian);

        if (tempPoints.length == 1) {
            viewer.entities.add({
                name: "线几何对象",
                polyline: {
                    positions: new Cesium.CallbackProperty(() => {
                        let c = Array.from(tempPoints);
                        if (_mousePos) {
                            c.push(_mousePos);
                        }
                        return c;
                    }, false),
                    clampToGround: true, //贴地
                    width: 1,
                    material: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                    depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                },
            });
        } else {
            //viewer.entities.removeAll();
            polygon2=viewer.entities.add({
                polygon: {
                    hierarchy: new Cesium.CallbackProperty(() => {
                        let poss = Array.from(tempPoints);
                        if (_mousePos) {
                            poss.push(_mousePos);
                        }
                        return new Cesium.PolygonHierarchy(poss);
                    }, false),

                    extrudedHeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    material: new Cesium.Color.fromCssColorString("#FD1B03").withAlpha(0.8),
                    //clampToGround: true,
                },
                polyline: {
                    positions: new Cesium.CallbackProperty(() => {
                        let c = Array.from(tempPoints);
                        if (_mousePos) {
                            c.push(_mousePos);
                            c.push(c[0]); //与第一个点相连
                        }
                        return c;
                    }, false),
                    clampToGround: true, //贴地
                    width: 2,
                    material: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                    depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                        color: new Cesium.Color.fromCssColorString("#FDE703"),
                    }),
                },
            });
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    //鼠标移动事件
    // handler.setInputAction((e) => {
    //     let p = viewer.scene.pickPosition(e.endPosition);
    //     if (!p) return;
    //     _mousePos = p;
    // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    //右键点击操作
    handler.setInputAction(function(click) {
        let cartesian = viewer.camera.pickEllipsoid(
            click.position,
            viewer.scene.globe.ellipsoid
        );

        if (cartesian) {
            let tempLength = tempPoints.length;
            if (tempLength < 3) {
                alert("请选择3个以上的点再执行闭合操作命令");
            } else {
                //viewer.entities.removeAll();

                polygon1=viewer.entities.add({
                    polyline: {

                        positions: new Cesium.CallbackProperty(() => {
                            let c = Array.from(tempPoints);
                            c.push(c[0]);
                            return c;
                        }, false),
                        clampToGround: true, //贴地
                        width: 2,
                        material: new Cesium.PolylineDashMaterialProperty({
                            color: new Cesium.Color.fromCssColorString("#FDE703"),
                        }),
                        depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
                            color: new Cesium.Color.fromCssColorString("#FDE703"),
                        }),
                    },
                    polygon: {
                        name: "面几何对象",
                        hierarchy: tempPoints,
                        extrudedHeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                        material: new Cesium.Color.fromCssColorString("#FD1B03").withAlpha(1),
                        clampToGround: true,

                    },


                });
                var summx=0;
                var summy=0;
                var summz=0;
                for (var i=0;i< tempPoints.length;i++){

                    summx+=tempPoints[i].x ;
                    summy+=tempPoints[i].y ;
                    summz+=tempPoints[i].z ;
                }
                let  position1 =  {x:summx/tempPoints.length,y:summy/tempPoints.length,z:summz/tempPoints.length}
                //polyline1.position=position1;
                var polyPositions = polygon1.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
                var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center;//中心点
                polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
                // polygon1.position = polyCenter;
                // polygon1.label={
                //
                //             text: `${mianid}号面`,
                //             font: '20px sans-serif', // 字体大小
                //             style: Cesium.LabelStyle.FILL_AND_OUTLINE, // 字体样式
                //             fillColor: new Cesium.Color.fromCssColorString("#0D2DF8"), // 字体填充色
                //             outlineWidth: 1,  // 字体外圈线宽度（同样也有颜色可设置）
                //             outlineColor: new Cesium.Color.fromCssColorString("#ffffff"),
                //             verticalOrigin: Cesium.VerticalOrigin.TOP, // 垂直位置
                //             pixelOffset: new Cesium.Cartesian2(0, 15),  // 中心位置
                //             disableDepthTestDistance: Number.POSITIVE_INFINITY
                //         }
                polygon2.position = polyCenter;

                polygon2.label={
                    text: `${mianid}号面`,
                    // font: '20px sans-serif', // 字体大小
                    // style: Cesium.LabelStyle.FILL_AND_OUTLINE, // 字体样式
                    // fillColor: new Cesium.Color.fromCssColorString("#0D2DF8"), // 字体填充色
                    // outlineWidth: 1,  // 字体外圈线宽度（同样也有颜色可设置）
                    // outlineColor: new Cesium.Color.fromCssColorString("#ffffff"),
                    // verticalOrigin: Cesium.VerticalOrigin.TOP, // 垂直位置
                    // pixelOffset: new Cesium.Cartesian2(0, 0),  // 中心位置
                    // disableDepthTestDistance: Number.POSITIVE_INFINITY
                    color : Cesium.Color.fromCssColorString('#E73C18'),
                    font:'normal 32px MicroSoft YaHei',
                    showBackground : true,
                    scale : 0.5,
                    disableDepthTestDistance: Number.POSITIVE_INFINITY,
                    //horizontalOrigin : Cesium.HorizontalOrigin.LEFT_CLICK,
                    //verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                    //disableDepthTestDistance : 100000.0,
                    heightReference : Cesium.HeightReference.CLAMP_TO_GROUND, // 高度参考为贴地
                    clampToGround:true  //是否贴地
                }


                $("#mianxxxx").show();
                $("#midbutton").click(function(){
                    var value=$("#midinput").val();

                    if (value.length>0){
                        polygon2. label.text._value=value;
                        mtd44.innerHTML =value;

                    }else {
                        alert("不能为空")
                    }

                })

                $('#tianchong1').click(function (){

                    // polygon2.polygon.material = new Cesium.CheckerboardMaterialProperty({
                    //     evenColor : Cesium.Color.WHITE,
                    //     oddColor : Cesium.Color.BLACK,
                    //     repeat : new Cesium.Cartesian2(4, 4)
                    // });
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/qipan.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });

                    $("#mianimg_cbl").attr("src", "images/qipan.png");
                })

                $('#tianchong11').click(function (){

                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/taiowen.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/taiowen.png");
                })
                $('#tianchong10').click(function (){

                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/qipan.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/qipan.png");
                })

                $('#tianchong2').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/taiowen.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/taiowen.png");
                })

                $('#tianchong3').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/网格.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/网格.png");
                })

                $('#tianchong4').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/编织物.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/编织物.png");
                })

                $('#tianchong5').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/纸袋.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });

                    $("#mianimg_cbl").attr("src", "images/纸袋.png");
                })

                $('#tianchong6').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/草纸.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/草纸.png");
                })

                $('#tianchong7').click(function (){
                    //完整的这么写
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/浅色横线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/浅色横线.png");
                })

                $('#tianchong8').click(function (){
                    //完整的这么写
                    // polygon2.polygon.material = new Cesium.GridMaterialProperty({
                    //     color : Cesium.Color.YELLOW,
                    //     cellAlpha : 0.2,
                    //     lineCount : new Cesium.Cartesian2(8, 8),
                    //     lineThickness : new Cesium.Cartesian2(2.0, 2.0)
                    // });
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/浅色竖线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/浅色竖线.png");
                })

                $('#tianchong9').click(function (){
                    polygon2.polygon.material=new Cesium.ImageMaterialProperty({
                        image: 'images/宽下对角线.png', // 替换为你的图片路径
                        // transparent: true // 让图片支持透明通道
                        repeat: new Cesium.Cartesian2(1.0, 1.0)
                    });
                    $("#mianimg_cbl").attr("src", "images/宽下对角线.png");
                })
                mtd44.innerHTML=mianid+"号面";
                layui.use('colorpicker', function () {
                    var colorpicker = layui.colorpicker;
                    //渲染
                    var aa = colorpicker.render({
                        elem: '#mysxz',  //绑定元素
                        format: 'rgb',
                        alpha: true,
                        done: function (color) {
                            redd=color.match(/\((.+?)\)/g)[0].split(",")[0].split("(",3)[1]/255;
                            greenn=color.match(/\((.+?)\)/g)[0].split(",")[1]/255;
                            bulee=color.match(/\((.+?)\)/g)[0].split(",")[2]/255;
                            polygon1._polygon._material._color._value.red=redd;
                            polygon1._polygon._material._color._value.blue=bulee;
                            polygon1._polygon._material._color._value.green=greenn;
                            polygon1.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);
                            polygon2.polygon.material=new Cesium.Color(redd, greenn, bulee, 1);
                            console.log(color)
                            $("#miancolor_cbl").css("background-color",color)
                            //point._point._color._value=color;
                            //console.log(position)
                            //譬如你可以在回调中把得到的 color 赋值给表单
                        }

                    })
                })

                handler.destroy(); //关闭事件句柄
                handler = null;
                body.style.cursor = "default";
            }
        }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

}


function guanxian(){

    let tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: 'http://3510b38g11.zicp.fun:13894/qingxie/smartminepipeline/red_long/tileset.json', //数据地址
        // maximumScreenSpaceError: 2, //最大的屏幕空间误差
        // maximumNumberOfLoadedTiles: 1000, //最大加载瓦片个数
        // modelMatrix: m, //形状矩阵
        modelMatrix: Cesium.Matrix4.fromArray([0.9864398675933796,-0.1302035259989476,0.09991711284758875,0,0.11051854643637493,0.9770485749676759,0.1821036327128731,0,-0.12133440779905415,-0.16859158926552542,0.9781895713577078,0,-4083.017168224789,-3268.634292630013,-2300.52889355924,1]),
    }));
    // tileset.style=new Cesium.Cesium3DTileStyle({
    //     color : {
    //         conditions : [
    //             // ['true', 'color("yellow")']
    //             // ['true', 'color(Cesium.Color(255,255,255,1))']
    //
    //             ['true', 'color("black", 0.5)']
    //         ]
    //     },
    //     show:true,
    // }),
    viewer.flyTo(tileset);
}

function CloseEntities(){
    // 根据entity（实体）对象删除
    //viewer.entities.remove()
    // 根据ID删除
    if (handler){
        //移除点击事件
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
    }

    for(var i=101;i<107;i++){
        viewer.entities.removeById(i);
        // console.log(i)
    }


    //viewer.entities.removeById();
    // 删除全部
    viewer.entities.removeAll()
    $('#moxing').hide();
    kuangqu()
    visible()
}

//裁剪


